diff options
Diffstat (limited to 'jstests/perf')
-rw-r--r--[-rwxr-xr-x] | jstests/perf/compact_speed_test.js | 33 | ||||
-rw-r--r-- | jstests/perf/find1.js | 89 | ||||
-rw-r--r-- | jstests/perf/geo_near1.js | 7 | ||||
-rw-r--r-- | jstests/perf/index1.js | 24 | ||||
-rw-r--r-- | jstests/perf/mr_bench.js | 77 | ||||
-rw-r--r-- | jstests/perf/remove1.js | 52 | ||||
-rw-r--r-- | jstests/perf/v8_mapreduce.js | 35 |
7 files changed, 159 insertions, 158 deletions
diff --git a/jstests/perf/compact_speed_test.js b/jstests/perf/compact_speed_test.js index 61733f104c2..440affd390b 100755..100644 --- a/jstests/perf/compact_speed_test.js +++ b/jstests/perf/compact_speed_test.js @@ -1,20 +1,23 @@ if (1) { - t = db.compactspeedtest; t.drop(); - var obj = { x: 1, y: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", z: [1, 2] }; + var obj = { + x: 1, + y: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + z: [1, 2] + }; var start = new Date(); function timed() { db.getLastError(); var dt = (new Date()) - start; - //print("time: " + dt); + // print("time: " + dt); start = new Date(); return dt; } - //print("adding data"); + // print("adding data"); var N = 100000; if (db.adminCommand("buildInfo").debug) N = 10000; @@ -25,27 +28,27 @@ if (1) { } var a = timed(); - //print("index"); - t.ensureIndex({ x: 1 }); - //print("index"); - t.ensureIndex({ y: 1 }); - //print("index"); - t.ensureIndex({ z: 1 }); + // print("index"); + t.ensureIndex({x: 1}); + // print("index"); + t.ensureIndex({y: 1}); + // print("index"); + t.ensureIndex({z: 1}); a += timed(); - //print("count:" + t.count()); + // print("count:" + t.count()); timed(); { - //print("compact"); - var res = db.runCommand({ compact: 'compactspeedtest', dev: true }); + // print("compact"); + var res = db.runCommand({compact: 'compactspeedtest', dev: true}); b = timed(); - //printjson(res); + // printjson(res); assert(res.ok); - //print("validate"); + // print("validate"); var v = t.validate(true); assert(v.ok); diff --git a/jstests/perf/find1.js b/jstests/perf/find1.js index ecd94e52579..6a9d3b75355 100644 --- a/jstests/perf/find1.js +++ b/jstests/perf/find1.js @@ -10,21 +10,21 @@ function testSetup(dbConn) { var t = dbConn[collection_name]; t.drop(); - for (var i=0; i<size; i++){ - t.save({ num : i }); - if (i == 0 ) - t.ensureIndex( { num : 1 } ); + for (var i = 0; i < size; i++) { + t.save({num: i}); + if (i == 0) + t.ensureIndex({num: 1}); } } -function resetQueryCache( db ) { - db[ collection_name ].createIndex( { a: 1 }, "dumbIndex" ); - db[ collection_name ].dropIndex( "dumbIndex" ); +function resetQueryCache(db) { + db[collection_name].createIndex({a: 1}, "dumbIndex"); + db[collection_name].dropIndex("dumbIndex"); } -function between( low, high, val, msg ) { - assert( low < val, msg ); - assert( val < high, msg ); +function between(low, high, val, msg) { + assert(low < val, msg); + assert(val < high, msg); } /** @@ -32,56 +32,51 @@ function between( low, high, val, msg ) { * from front of collection vs end, using $lt */ function testFindLTFrontBack(dbConn) { - var results = {}; var t = dbConn[collection_name]; - resetQueryCache( dbConn ); - results.oneInOrderLTFirst = Date.timeFunc( - function(){ - assert( t.find( { num : {$lt : 20} } ).sort( { num : 1 } ).limit(10).toArray().length == 10); - } , calls ); - - resetQueryCache( dbConn ); - results.oneInOrderLTLast = Date.timeFunc( - function(){ - assert( t.find( { num : {$lt : size-20 }} ).sort( { num : 1 } ).limit(10).toArray().length == 10); - } , calls ); - - - between( 0.9, 1.1, results.oneInOrderLTFirst / results.oneInOrderLTLast, - "first / last (" + results.oneInOrderLTFirst + " / " + results.oneInOrderLTLast + " ) = " + - results.oneInOrderLTFirst / results.oneInOrderLTLast + " not in [0.9, 1.1]" ); + resetQueryCache(dbConn); + results.oneInOrderLTFirst = Date.timeFunc(function() { + assert(t.find({num: {$lt: 20}}).sort({num: 1}).limit(10).toArray().length == 10); + }, calls); + + resetQueryCache(dbConn); + results.oneInOrderLTLast = Date.timeFunc(function() { + assert(t.find({num: {$lt: size - 20}}).sort({num: 1}).limit(10).toArray().length == 10); + }, calls); + + between(0.9, + 1.1, + results.oneInOrderLTFirst / results.oneInOrderLTLast, + "first / last (" + results.oneInOrderLTFirst + " / " + results.oneInOrderLTLast + + " ) = " + results.oneInOrderLTFirst / results.oneInOrderLTLast + + " not in [0.9, 1.1]"); } - - /** * Tests fetching a set of 10 objects in sorted order, comparing getting * from front of collection vs end */ function testFindGTFrontBack(dbConn) { - var results = {}; var t = dbConn[collection_name]; - - resetQueryCache( dbConn ); - results.oneInOrderGTFirst = Date.timeFunc( - function(){ - assert( t.find( { num : {$gt : 5} } ).sort( { num : 1 } ).limit(10).toArray().length == 10); - } , calls ); - - resetQueryCache( dbConn ); - results.oneInOrderGTLast = Date.timeFunc( - function(){ - assert( t.find( { num : {$gt : size-20 }} ).sort( { num : 1 } ).limit(10).toArray().length == 10); - } , calls ); - - - between( 0.25, 4.0, results.oneInOrderGTFirst / results.oneInOrderGTLast, - "first / last (" + results.oneInOrderGTFirst + " / " + results.oneInOrderGTLast + " ) = " + - results.oneInOrderGTFirst / results.oneInOrderGTLast + " not in [0.25, 4.0]" ); + resetQueryCache(dbConn); + results.oneInOrderGTFirst = Date.timeFunc(function() { + assert(t.find({num: {$gt: 5}}).sort({num: 1}).limit(10).toArray().length == 10); + }, calls); + + resetQueryCache(dbConn); + results.oneInOrderGTLast = Date.timeFunc(function() { + assert(t.find({num: {$gt: size - 20}}).sort({num: 1}).limit(10).toArray().length == 10); + }, calls); + + between(0.25, + 4.0, + results.oneInOrderGTFirst / results.oneInOrderGTLast, + "first / last (" + results.oneInOrderGTFirst + " / " + results.oneInOrderGTLast + + " ) = " + results.oneInOrderGTFirst / results.oneInOrderGTLast + + " not in [0.25, 4.0]"); } testSetup(db); diff --git a/jstests/perf/geo_near1.js b/jstests/perf/geo_near1.js index 36cb9da2cfb..c16c41bd080 100644 --- a/jstests/perf/geo_near1.js +++ b/jstests/perf/geo_near1.js @@ -1,11 +1,10 @@ var t = db.bench.geo_near1; t.drop(); -var numPts = 1000*1000; +var numPts = 1000 * 1000; - -for (var i=0; i < numPts; i++){ +for (var i = 0; i < numPts; i++) { x = (Math.random() * 100) - 50; y = (Math.random() * 100) - 50; - t.insert({loc: [x,y], i: i}); + t.insert({loc: [x, y], i: i}); } diff --git a/jstests/perf/index1.js b/jstests/perf/index1.js index 7bcf4b71ab1..ecb749069b9 100644 --- a/jstests/perf/index1.js +++ b/jstests/perf/index1.js @@ -2,19 +2,23 @@ t = db.perf.index1; t.drop(); -for ( var i=0; i<100000; i++ ){ - t.save( { x : i } ); +for (var i = 0; i < 100000; i++) { + t.save({x: i}); } t.findOne(); -printjson( db.serverStatus().mem ); +printjson(db.serverStatus().mem); -for ( var i=0; i<5; i++ ){ - nonu = Date.timeFunc( function(){ t.ensureIndex( { x : 1 } ); } ); - t.dropIndex( { x : 1 } ); - u = Date.timeFunc( function(){ t.ensureIndex( { x : 1 }, { unique : 1 } ); } ); - t.dropIndex( { x : 1 } ); - print( "non unique: " + nonu + " unique: " + u ); - printjson( db.serverStatus().mem ); +for (var i = 0; i < 5; i++) { + nonu = Date.timeFunc(function() { + t.ensureIndex({x: 1}); + }); + t.dropIndex({x: 1}); + u = Date.timeFunc(function() { + t.ensureIndex({x: 1}, {unique: 1}); + }); + t.dropIndex({x: 1}); + print("non unique: " + nonu + " unique: " + u); + printjson(db.serverStatus().mem); } diff --git a/jstests/perf/mr_bench.js b/jstests/perf/mr_bench.js index 38ef57f0835..c48a9ddbe36 100644 --- a/jstests/perf/mr_bench.js +++ b/jstests/perf/mr_bench.js @@ -2,15 +2,18 @@ t = db.mr_bench; t.drop(); -function getRandomStr(L){ - var s= ''; - var randomchar=function(){ - var n= Math.floor(Math.random()*62); - if(n<10) return n; //1-10 - if(n<36) return String.fromCharCode(n+55); //A-Z - return String.fromCharCode(n+61); //a-z +function getRandomStr(L) { + var s = ''; + var randomchar = function() { + var n = Math.floor(Math.random() * 62); + if (n < 10) + return n; // 1-10 + if (n < 36) + return String.fromCharCode(n + 55); // A-Z + return String.fromCharCode(n + 61); // a-z }; - while(s.length< L) s+= randomchar(); + while (s.length < L) + s += randomchar(); return s; } @@ -22,36 +25,37 @@ while (largeStr.length < 512) { } largeStr = largeStr.substr(512); -for ( i = 0; i < 100000; ++i ) { +for (i = 0; i < 100000; ++i) { t.save({rand: getRandomStr(20), same: "the same string", str: largeStr}); } emit = printjson; count = t.count(); -function d( x ){ - printjson( x ); +function d(x) { + printjson(x); } -m = function(){ +m = function() { emit(this.rand, {id: this._id, str: this.str}); }; -m2 = function(){ +m2 = function() { emit(this.same, this.rand); }; -r = function(k,vals) { - var tmp = {}; - vals.forEach(function(i) { - if(typeof(i) == 'string') { - tmp[i] = true; +r = function(k, vals) { + var tmp = {}; + vals.forEach(function(i) { + if (typeof(i) == 'string') { + tmp[i] = true; } else { - for(var z in i) tmp[z] = true; + for (var z in i) + tmp[z] = true; } - }); + }); - return tmp; + return tmp; }; // following time limits are passing fine on a laptop with a debug build @@ -59,25 +63,22 @@ r = function(k,vals) { // 1st MR just uses random unique keys, with no reduce involved // this should be straightforward for perf, but could lead to OOM if settings are bad -assert.time( -function() { -res = db.runCommand( { mapreduce : "mr_bench" , map : m , reduce : r , out : "mr_bench_out" } ); -d( res ); -assert.eq( count , res.counts.input , "A" ); -x = db[res.result]; -assert.eq( count , x.find().count() , "B" ); -return 1; +assert.time(function() { + res = db.runCommand({mapreduce: "mr_bench", map: m, reduce: r, out: "mr_bench_out"}); + d(res); + assert.eq(count, res.counts.input, "A"); + x = db[res.result]; + assert.eq(count, x.find().count(), "B"); + return 1; }, "unique key mr", 15000); // 2nd MR emits the same key, and a unique value is added as key to same object // if object is kept in ram and being reduced, this can be really slow -assert.time( -function() { -res = db.runCommand( { mapreduce : "mr_bench" , map : m2 , reduce : r , out : "mr_bench_out" } ); -d( res ); -assert.eq( count , res.counts.input , "A" ); -x = db[res.result]; -assert.eq( 1 , x.find().count() , "B" ); -return 1; +assert.time(function() { + res = db.runCommand({mapreduce: "mr_bench", map: m2, reduce: r, out: "mr_bench_out"}); + d(res); + assert.eq(count, res.counts.input, "A"); + x = db[res.result]; + assert.eq(1, x.find().count(), "B"); + return 1; }, "single key mr", 20000); - diff --git a/jstests/perf/remove1.js b/jstests/perf/remove1.js index 3e1a1a6b71c..09f1948572b 100644 --- a/jstests/perf/remove1.js +++ b/jstests/perf/remove1.js @@ -10,16 +10,16 @@ var msg = "Hello from remove test"; function testSetup(dbConn) { var t = dbConn[collection_name]; t.drop(); - t.ensureIndex( { num : 1 } ); + t.ensureIndex({num: 1}); - for (var i=0; i<size; i++){ - t.save({ num : i, msg : msg }); + for (var i = 0; i < size; i++) { + t.save({num: i, msg: msg}); } } -function between( low, high, val, msg ) { - assert( low < val, msg ); - assert( val < high, msg ); +function between(low, high, val, msg) { + assert(low < val, msg); + assert(val < high, msg); } /** @@ -29,40 +29,36 @@ function between( low, high, val, msg ) { * @param dbConn */ function testRemoveWithMultiField(dbConn) { - var results = {}; var t = dbConn[collection_name]; testSetup(dbConn); - t.remove( {num:0 } ); - results.indexOnly = Date.timeFunc( - function(){ - for (var i = 1; i < removals; i++) { - t.remove({num : i}); - } - - t.findOne(); + t.remove({num: 0}); + results.indexOnly = Date.timeFunc(function() { + for (var i = 1; i < removals; i++) { + t.remove({num: i}); } - ); + + t.findOne(); + }); testSetup(dbConn); - - t.remove( {num: 0, msg: msg } ); - results.withAnother = Date.timeFunc( - function(){ - for (var i = 1; i < removals; i++) { - t.remove({num : i, msg : msg}); - } - t.findOne(); + t.remove({num: 0, msg: msg}); + results.withAnother = Date.timeFunc(function() { + for (var i = 1; i < removals; i++) { + t.remove({num: i, msg: msg}); } - ); + t.findOne(); + }); - between( 0.65, 1.35, (results.indexOnly / results.withAnother), - "indexOnly / withAnother (" + results.indexOnly + " / " + results.withAnother + " ) = " + - results.indexOnly / results.withAnother + " not in [0.65, 1.35]" ); + between(0.65, + 1.35, + (results.indexOnly / results.withAnother), + "indexOnly / withAnother (" + results.indexOnly + " / " + results.withAnother + + " ) = " + results.indexOnly / results.withAnother + " not in [0.65, 1.35]"); } testRemoveWithMultiField(db); diff --git a/jstests/perf/v8_mapreduce.js b/jstests/perf/v8_mapreduce.js index b98cdc5fc0d..7ff329c5284 100644 --- a/jstests/perf/v8_mapreduce.js +++ b/jstests/perf/v8_mapreduce.js @@ -2,20 +2,21 @@ // Our server and client need to be running V8 and the host we are running on needs at least two // cores. Update this if you are testing more than three threads in parallel. -if (/V8/.test(interpreterVersion()) && - db.runCommand({buildinfo:1}).javascriptEngine == "V8" && +if (/V8/.test(interpreterVersion()) && db.runCommand({buildinfo: 1}).javascriptEngine == "V8" && db.hostInfo().system.numCores >= 2) { - // function timeSingleThread // Description: Gathers data about how long it takes to run a given job // Args: job - job to run // tid - thread id passed as an argument to the job, default 0 // Returns: { threadStart : <time job started> , threadEnd : <time job completed> } - var timeSingleThread = function (job, tid) { + var timeSingleThread = function(job, tid) { var tid = tid || 0; var threadStart = new Date(); job(tid); - return { "threadStart" : threadStart , "threadEnd" : new Date() }; + return { + "threadStart": threadStart, + "threadEnd": new Date() + }; }; // function timeMultipleThreads @@ -28,7 +29,7 @@ if (/V8/.test(interpreterVersion()) && // threadEnd : <time elapsed before thread completed work> } , // ... // ] - var timeMultipleThreads = function (job, nthreads, stagger) { + var timeMultipleThreads = function(job, nthreads, stagger) { var i = 0; var threads = []; @@ -59,7 +60,7 @@ if (/V8/.test(interpreterVersion()) && // Display and analysis helper functions - var getLastCompletion = function (threadTimes) { + var getLastCompletion = function(threadTimes) { var lastCompletion = 0; for (var i = 0; i < threadTimes.length; i++) { lastCompletion = Math.max(lastCompletion, threadTimes[i].threadEnd); @@ -71,14 +72,17 @@ if (/V8/.test(interpreterVersion()) && db.v8_parallel_mr_src.drop(); - for (j=0; j<100; j++) for (i=0; i<512; i++){ db.v8_parallel_mr_src.save({j:j, i:i});} + for (j = 0; j < 100; j++) + for (i = 0; i < 512; i++) { + db.v8_parallel_mr_src.save({j: j, i: i}); + } db.getLastError(); - var mrWorkFunction = function () { + var mrWorkFunction = function() { function verifyOutput(out) { - //printjson(out); + // printjson(out); assert.eq(out.counts.input, 51200, "input count is wrong"); assert.eq(out.counts.emit, 51200, "emit count is wrong"); assert.gt(out.counts.reduce, 99, "reduce count is wrong"); @@ -87,22 +91,21 @@ if (/V8/.test(interpreterVersion()) && function map() { if (this.j % 2 == 0) { - emit(this.i, this.j*this.j); - } - else { - emit(this.i, this.j+this.j); + emit(this.i, this.j * this.j); + } else { + emit(this.i, this.j + this.j); } } function reduce(key, values) { - values_halved = values.map(function (value) { + values_halved = values.map(function(value) { return value / 2; }); values_halved_sum = Array.sum(values_halved); return values_halved_sum; } - var out = db.v8_parallel_mr_src.mapReduce(map, reduce, { out : "v8_parallel_mr_out" }); + var out = db.v8_parallel_mr_src.mapReduce(map, reduce, {out: "v8_parallel_mr_out"}); verifyOutput(out); }; |