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. 17
      lib/datastore.js

@ -5,6 +5,7 @@
var customUtils = require('../lib/customUtils')
, fs = require('fs')
, path = require('path')
, Datastore = require('../lib/datastore')
, 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) {
customUtils.ensureDirectoryExists(path.dirname(filename), function () {

@ -3,32 +3,20 @@ var Datastore = require('../lib/datastore')
, fs = require('fs')
, path = require('path')
, async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time')
, profiler = new execTime('FIND BENCH')
, d = new Datastore(benchDb)
, program = require('commander')
, n
, commonUtilities = require('./commonUtilities')
, config = commonUtilities.getConfiguration(benchDb)
, 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.apply(commonUtilities.prepareDb, benchDb)
, function (cb) {
d.loadDatabase(function (err) {
if (err) { return cb(err); }
if (program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
cb();
});
}

@ -3,37 +3,26 @@ var Datastore = require('../lib/datastore')
, fs = require('fs')
, path = require('path')
, async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time')
, profiler = new execTime('FINDONE BENCH')
, d = new Datastore(benchDb)
, program = require('commander')
, n
, commonUtilities = require('./commonUtilities')
, config = commonUtilities.getConfiguration(benchDb)
, 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.apply(commonUtilities.prepareDb, benchDb)
, function (cb) {
d.loadDatabase(function (err) {
if (err) { return cb(err); }
if (program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
cb();
});
}
, function (cb) { profiler.beginProfiling(); return cb(); }
, async.apply(commonUtilities.insertDocs, d, n, profiler)
, function (cb) { setTimeout(function () {cb();}, 500); }
, async.apply(commonUtilities.findOneDocs, d, n, profiler)
], function (err) {
profiler.step("Benchmark finished");

@ -1,36 +1,20 @@
var Datastore = require('../lib/datastore')
, benchDb = 'workspace/insert.bench.db'
, async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time')
, profiler = new execTime('INSERT BENCH')
, d
, program = require('commander')
, n
, commonUtilities = require('./commonUtilities')
, config = commonUtilities.getConfiguration(benchDb)
, 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.apply(commonUtilities.prepareDb, benchDb)
, function (cb) {
d.loadDatabase(function (err) {
if (err) { return cb(err); }
if (program.withIndex) {
if (config.program.withIndex) {
d.ensureIndex({ fieldName: 'docNumber' });
n = 2 * n; // We will actually insert twice as many documents
// because the index is slower when the collection is already

@ -3,34 +3,20 @@ var Datastore = require('../lib/datastore')
, fs = require('fs')
, path = require('path')
, async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time')
, profiler = new execTime('REMOVE BENCH')
, d = new Datastore(benchDb)
, program = require('commander')
, n
, commonUtilities = require('./commonUtilities')
, config = commonUtilities.getConfiguration(benchDb)
, 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.apply(commonUtilities.prepareDb, benchDb)
, function (cb) {
d.loadDatabase(function (err) {
if (err) { return cb(err); }
if (program.withIndex) {
d.ensureIndex({ fieldName: 'docNumber' });
}
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
cb();
});
}

@ -3,42 +3,26 @@ var Datastore = require('../lib/datastore')
, fs = require('fs')
, path = require('path')
, async = require('async')
, commonUtilities = require('./commonUtilities')
, execTime = require('exec-time')
, profiler = new execTime('UPDATE BENCH')
, d = new Datastore(benchDb)
, program = require('commander')
, n
, commonUtilities = require('./commonUtilities')
, config = commonUtilities.getConfiguration(benchDb)
, 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.apply(commonUtilities.prepareDb, benchDb)
, function (cb) {
d.loadDatabase(function (err) {
if (err) { return cb(err); }
if (program.withIndex) {
d.ensureIndex({ fieldName: 'docNumber' });
}
if (config.program.withIndex) { d.ensureIndex({ fieldName: 'docNumber' }); }
cb();
});
}
, function (cb) { profiler.beginProfiling(); return cb(); }
, async.apply(commonUtilities.insertDocs, d, n, profiler)
// CHECK THAT MULTIPLE LOAD DATABASE DONT SCREW INDEXES
// Test with update only one document
, function (cb) { profiler.step('MULTI: FALSE'); return cb(); }
, async.apply(commonUtilities.updateDocs, { multi: false }, d, n, profiler)

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

Loading…
Cancel
Save