JS Benchmarking Harness

This benchRun command is designed as a QA baseline perf measurement tool, not designed to be a “benchmark”.

CODE

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 );
}

Dynamic Values

// 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 );

Options

host

The hostname of the machine mongod is running on (defaults to localhost).

username

The username to use when authenticating to mongod (only use if running with auth).

password

The password to use when authenticating to mongod (only use if running with auth).

db

The database to authenticate to (only necessary if running with auth).

ops

A list of objects describing the operations to run (documented below).

parallel

The number of threads to run (defaults to single thread).

seconds

The amount of time to run the tests for (defaults to one second).

Operation Options

ns

The namespace of the collection you are running the operation on, should be of the form "db.collection".

op

The type of operation can be "findOne", "insert", "update", "remove", "createIndex", "dropIndex" or "command".

query

The query object to use when querying or updating documents.

update

The update object (same as 2nd argument of update() function).

doc

The document to insert into the database (only for insert and remove).

safe

boolean specifying whether to use safe writes (only for update and insert).

Dynamic Operators

{ "#RAND_INT" : [ min , max , <multiplier> ] }
  • [ 0 , 10 , 4 ] would produce random numbers between 0 and 10 and then multiply by 4.
{ "#RAND_STRING" : [ length ] }
  • [ 3 ] would produce a string of 3 random characters.

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: