New parameters for all benchamrsk

pull/2/head
Louis Chatriot 12 years ago
parent 518e5b8285
commit 8f82ab39a3
  1. 36
      benchmarks/commonUtilities.js
  2. 22
      benchmarks/find.js
  3. 23
      benchmarks/findOne.js
  4. 26
      benchmarks/insert.js
  5. 24
      benchmarks/remove.js
  6. 26
      benchmarks/update.js
  7. 15
      lib/datastore.js

@ -5,6 +5,7 @@
var customUtils = require('../lib/customUtils') var customUtils = require('../lib/customUtils')
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, Datastore = require('../lib/datastore')
, executeAsap // process.nextTick or setImmediate depending on your Node version , executeAsap // process.nextTick or setImmediate depending on your Node version
; ;
@ -16,7 +17,40 @@ try {
/** /**
* Ensure the workspace exists and the db is empty * Configure the benchmark
*/
module.exports.getConfiguration = function (benchDb) {
var d, n
, program = require('commander')
;
program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Use an index')
.option('-p --with-pipeline', 'Use pipelining')
.option('-m --in-memory', 'Test with an in-memory only store')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log(program.withPipeline ? "Use an pipelining" : "Don't use pipelining");
console.log(program.inMemory ? "Use an in-memory datastore" : "Use a persistent datastore");
console.log("----------------------------");
d = new Datastore({ filename: benchDb
, pipeline: program.withPipeline
, inMemoryOnly: program.inMemory
});
return { n: n, d: d, program: program };
}
/**
* Ensure the workspace exists and the db datafile is empty
*/ */
module.exports.prepareDb = function (filename, cb) { module.exports.prepareDb = function (filename, cb) {
customUtils.ensureDirectoryExists(path.dirname(filename), function () { customUtils.ensureDirectoryExists(path.dirname(filename), function () {

@ -3,32 +3,20 @@ var Datastore = require('../lib/datastore')
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, async = require('async') , async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('FIND BENCH') , profiler = new execTime('FIND BENCH')
, d = new Datastore(benchDb) , commonUtilities = require('./commonUtilities')
, program = require('commander') , config = commonUtilities.getConfiguration(benchDb)
, n , d = config.d
, n = config.n
; ;
program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Test with an index')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log("----------------------------");
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { , function (cb) {
d.loadDatabase(function (err) { d.loadDatabase(function (err) {
if (err) { return cb(err); } if (err) { return cb(err); }
if (program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); } if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
cb(); cb();
}); });
} }

@ -3,37 +3,26 @@ var Datastore = require('../lib/datastore')
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, async = require('async') , async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('FINDONE BENCH') , profiler = new execTime('FINDONE BENCH')
, d = new Datastore(benchDb) , commonUtilities = require('./commonUtilities')
, program = require('commander') , config = commonUtilities.getConfiguration(benchDb)
, n , d = config.d
, n = config.n
; ;
program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Test with an index')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log("----------------------------");
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { , function (cb) {
d.loadDatabase(function (err) { d.loadDatabase(function (err) {
if (err) { return cb(err); } if (err) { return cb(err); }
if (program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); } if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
cb(); cb();
}); });
} }
, function (cb) { profiler.beginProfiling(); return cb(); } , function (cb) { profiler.beginProfiling(); return cb(); }
, async.apply(commonUtilities.insertDocs, d, n, profiler) , async.apply(commonUtilities.insertDocs, d, n, profiler)
, function (cb) { setTimeout(function () {cb();}, 500); }
, async.apply(commonUtilities.findOneDocs, d, n, profiler) , async.apply(commonUtilities.findOneDocs, d, n, profiler)
], function (err) { ], function (err) {
profiler.step("Benchmark finished"); profiler.step("Benchmark finished");

@ -1,36 +1,20 @@
var Datastore = require('../lib/datastore') var Datastore = require('../lib/datastore')
, benchDb = 'workspace/insert.bench.db' , benchDb = 'workspace/insert.bench.db'
, async = require('async') , async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('INSERT BENCH') , profiler = new execTime('INSERT BENCH')
, d , commonUtilities = require('./commonUtilities')
, program = require('commander') , config = commonUtilities.getConfiguration(benchDb)
, n , d = config.d
, n = config.n
; ;
program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Use an index')
.option('-p --with-pipeline', 'Use pipelining')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log(program.withPipeline ? "Use an pipelining" : "Don't use pipelining");
console.log("----------------------------");
d = new Datastore({ filename: benchDb, pipeline: program.withPipeline });
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { , function (cb) {
d.loadDatabase(function (err) { d.loadDatabase(function (err) {
if (err) { return cb(err); } if (err) { return cb(err); }
if (program.withIndex) { if (config.program.withIndex) {
d.ensureIndex({ fieldName: 'docNumber' }); d.ensureIndex({ fieldName: 'docNumber' });
n = 2 * n; // We will actually insert twice as many documents n = 2 * n; // We will actually insert twice as many documents
// because the index is slower when the collection is already // because the index is slower when the collection is already

@ -3,34 +3,20 @@ var Datastore = require('../lib/datastore')
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, async = require('async') , async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('REMOVE BENCH') , profiler = new execTime('REMOVE BENCH')
, d = new Datastore(benchDb) , commonUtilities = require('./commonUtilities')
, program = require('commander') , config = commonUtilities.getConfiguration(benchDb)
, n , d = config.d
, n = config.n
; ;
program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Test with an index')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log("----------------------------");
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { , function (cb) {
d.loadDatabase(function (err) { d.loadDatabase(function (err) {
if (err) { return cb(err); } if (err) { return cb(err); }
if (program.withIndex) { if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
d.ensureIndex({ fieldName: 'docNumber' });
}
cb(); cb();
}); });
} }

@ -3,42 +3,26 @@ var Datastore = require('../lib/datastore')
, fs = require('fs') , fs = require('fs')
, path = require('path') , path = require('path')
, async = require('async') , async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time') , execTime = require('exec-time')
, profiler = new execTime('UPDATE BENCH') , profiler = new execTime('UPDATE BENCH')
, d = new Datastore(benchDb) , commonUtilities = require('./commonUtilities')
, program = require('commander') , config = commonUtilities.getConfiguration(benchDb)
, n , d = config.d
, n = config.n
; ;
program
.option('-n --number [number]', 'Size of the collection to test on', parseInt)
.option('-i --with-index', 'Test with an index')
.parse(process.argv);
n = program.number || 10000;
console.log("----------------------------");
console.log("Test with " + n + " documents");
console.log(program.withIndex ? "Use an index" : "Don't use an index");
console.log("----------------------------");
async.waterfall([ async.waterfall([
async.apply(commonUtilities.prepareDb, benchDb) async.apply(commonUtilities.prepareDb, benchDb)
, function (cb) { , function (cb) {
d.loadDatabase(function (err) { d.loadDatabase(function (err) {
if (err) { return cb(err); } if (err) { return cb(err); }
if (program.withIndex) { if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
d.ensureIndex({ fieldName: 'docNumber' });
}
cb(); cb();
}); });
} }
, function (cb) { profiler.beginProfiling(); return cb(); } , function (cb) { profiler.beginProfiling(); return cb(); }
, async.apply(commonUtilities.insertDocs, d, n, profiler) , async.apply(commonUtilities.insertDocs, d, n, profiler)
// CHECK THAT MULTIPLE LOAD DATABASE DONT SCREW INDEXES
// Test with update only one document // Test with update only one document
, function (cb) { profiler.step('MULTI: FALSE'); return cb(); } , function (cb) { profiler.step('MULTI: FALSE'); return cb(); }
, async.apply(commonUtilities.updateDocs, { multi: false }, d, n, profiler) , async.apply(commonUtilities.updateDocs, { multi: false }, d, n, profiler)

@ -250,7 +250,11 @@ Datastore.prototype._loadDatabase = function (cb) {
}; };
Datastore.prototype.loadDatabase = function () { Datastore.prototype.loadDatabase = function () {
if (this.pipeline) {
this.persistenceExecutor.push({ this: this, fn: this._loadDatabase, arguments: arguments });
} else {
this.executor.push({ this: this, fn: this._loadDatabase, arguments: arguments }); this.executor.push({ this: this, fn: this._loadDatabase, arguments: arguments });
}
}; };
@ -337,12 +341,19 @@ Datastore.prototype._persistNewState = function (newDocs, cb) {
}); });
}; };
Datastore.prototype.persistNewState = function (newDocs, cb) { Datastore.prototype.persistNewState = function (newDocs, cb) {
if (this.inMemoryOnly) {
cb(); // No persistence
return;
}
if (this.pipeline) { if (this.pipeline) {
this.persistenceExecutor.push({ this: this, fn: this._persistNewState, arguments: [newDocs] }); this.persistenceExecutor.push({ this: this, fn: this._persistNewState, arguments: [newDocs] });
cb (); // Return right away with no error cb (); // Return right away with no error
} else { return;
this._persistNewState(newDocs, cb);
} }
// Default behaviour
this._persistNewState(newDocs, cb);
}; };

Loading…
Cancel
Save