-
Notifications
You must be signed in to change notification settings - Fork 5.6k
JavaScript Performance Testing Harness
This benchRun
command is designed as a QA baseline performance measurement tool; it is 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
} );
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
} );
print( "threads: 2\t insert/sec: " + res.insert );
-
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).
-
hideResults
Prevents results from each operation executed from being logged. Default value is
true
. Overridden by settingshowResult
on a specific operation. -
handleErrors
Prevents a thread from stopping on error. Default value is
false
. Overridden by settinghandleError
on a specific operation. -
hideErrors
Prevents errors from being logged. Default value is
false
. Overridden by settingshowError
for a specific operation. -
throwGLE
Causes
benchRun
to actually throw an exception on errors in updates/inserts/deletes rather than handling them. Default value isfalse
to havebenchRun
to handle the errors itself.throwGLE
can also be set on specific operations.
-
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"
,"find"
,"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
specifies whether to use safe writes (only for update and insert). -
delay
integer
specifies the time to wait between executing the operation. -
skip
Only applies to find operations.
integer
specifies the number of documents to skip in a query. -
limit
Only applies to find operations.
integer
specifies the number of elements a query should return. -
batchSize
Only applies to find operations.
integer
specifies the number of elements the returned cursor should cache. -
filter
Only applies to find operations. Document specifies which fields should be returned.
-
expected
Only applies to find operations.
integer
specifies the expected number of elements returned. If the count is not as expected the operation will throw an error. Turning on thehandleErrors
option allowsbenchRun
to continue if the count was not as expected. -
multi
boolean
specifies whether or not the update or delete should apply to multiple documents. Default value isfalse
. -
upsert
boolean
specifies whether or not an update operation should be run as an upsert. Default value isfalse
. -
key
Only works for and is required by the
createIndex
anddropIndex
operations. The definition for the index to create or drop. -
showResult
boolean
specifies whether to log the result of each call of the operation.
{ "#RAND_INT" : [ min , max , <multiplier> ] }
-
[ 0 , 10 , 4 ]
would produce random numbers between0
and10
and then multiply by4
.
{ "#RAND_STRING" : [ length ] }
-
[ 3 ]
would produce a string of3
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:
Getting started
Building
Testing
- Running Tests
- Writing Tests
- Writing Function-level Benchmarks
- Writing JavaScript Integration-level Performance Tests
- Running Bisect
- Running Minimized Jstestfuzz Tests
- Testing with Antithesis
Testing in Evergreen
Code Style
Server Internals