This benchRun command is designed as a QA baseline perf measurement tool, not designed to be a “benchmark”.
db.foo.drop();
db.foo.insert( { _id : 1 } )
ops = [{op: "findOne", ns: "test.foo", query: {_id: 1}},
{op: "update", ns: "test.foo", query: {_id: 1}, update: {$inc: {x: 1}}}]
for ( var x = 1; x <= 128; x *= 2) {
res = benchRun( {
parallel : x ,
seconds : 5 ,
ops : ops
} );
print( "threads: " + x + "\t queries/sec: " + res.query );
}
// benchmark updates using the $inc operator
res = benchRun( {
ops : [ {
ns : "test.foo" ,
op : "update" ,
query : { _id : { "#RAND_INT" : [ 0 , 100 ] } } ,
update : { $inc : { x : 1 } }
} ] ,
parallel : 2 ,
seconds : 1 ,
totals : true
} );
print( "threads: 2\t update/sec: " + res.update );
// benchmark inserts with random strings
res = benchRun( {
ops : [ {
ns : "test.foo" ,
op : "insert" ,
doc : { y : { "#RAND_STRING" : [ 10 ] } }
} ] ,
parallel : 2 ,
seconds : 1 ,
totals : true
} );
print( "threads: 2\t insert/sec: " + res.insert );
The hostname of the machine mongod is running on (defaults to localhost).
The username to use when authenticating to mongod (only use if running with auth).
The password to use when authenticating to mongod (only use if running with auth).
The database to authenticate to (only necessary if running with auth).
A list of objects describing the operations to run (documented below).
The number of threads to run (defaults to single thread).
The amount of time to run the tests for (defaults to one second).
The namespace of the collection you are running the operation on, should be of the form "db.collection".
The type of operation can be "findOne", "insert", "update", "remove", "createIndex", "dropIndex" or "command".
The query object to use when querying or updating documents.
The update object (same as 2nd argument of update() function).
The document to insert into the database (only for insert and remove).
boolean specifying whether to use safe writes (only for update and insert).
{ "#RAND_INT" : [ min , max , <multiplier> ] }
{ "#RAND_STRING" : [ length ] }
Dynamic operators generate random strings, random ints, etc but don’t work in second level objects, just main level.
This is fine:
var complexDoc3 = { info: "#RAND_STRING": [30] } }
This is only going to insert a value called "#RAND_STRING" with an array as a key:
var complexDoc3 = { info: { inner_field: { "#RAND_STRING": [30] } } }
More info: