Created
March 21, 2019 20:35
-
-
Save timwhitlock/4d5b6e33afc7fe9b00f860606bbccd3b to your computer and use it in GitHub Desktop.
bulkWrite benchmarks for different write concerns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function runTest( MongoDB\Driver\WriteConcern $writeConcern ){ | |
$bulk = new MongoDB\Driver\BulkWrite(['ordered'=>false]); | |
for( $i = 0; $i < 10000; $i++ ){ | |
$bulk->insert( [ | |
'time' => new MongoDB\BSON\UTCDateTime, | |
] ); | |
} | |
$manager = new MongoDB\Driver\Manager( 'mongodb://localhost:27017', [ | |
'username' => 'foo', | |
'password' => 'bar', | |
'authSource' => 'admin', | |
] ); | |
$bench = microtime(true); | |
$manager->executeBulkWrite( 'test.test', $bulk, [ 'writeConcern' => $writeConcern ] ); | |
$bench = microtime(true) - $bench; | |
printf("%u documents with w=%s j=%s took %f seconds\n", $bulk->count(), $writeConcern->getW(), $writeConcern->getJournal()?'true':'false', $bench ); | |
} | |
runTest( new MongoDB\Driver\WriteConcern(3,5000,true) ); | |
runTest( new MongoDB\Driver\WriteConcern(2,5000,true) ); | |
runTest( new MongoDB\Driver\WriteConcern(1,null,true) ); | |
runTest( new MongoDB\Driver\WriteConcern(1,null,false) ); | |
runTest( new MongoDB\Driver\WriteConcern(0,null,false) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
db version v3.4.20
git version: 447847d93d6e0a21b018d5df45528e815c7c13d8
db version v3.6.11
git version: b4339db12bf57ffee5b84a95c6919dbd35fe31c9