Files
elasticsearch-js/scripts/stupid-benchmark.js
Spencer Alger 5bb70fbe58 Moved the curl formatting into the log and changed the arguments for the log event listeneres to
receive both the "message" and the "curlCommand".

Added a "tracer" logger which allows you to create log files that a executable scripts. Those scripts
will write all of the log messages as script comments, and not comment out the curlCommands, so that they
can trace their application and use the generated script to recreate the issue.

Most changes are simply cased by adding the "unused" rule to jshint.
2013-11-15 19:10:45 -07:00

75 lines
1.7 KiB
JavaScript

var es = require('../src/elasticsearch');
var async = require('async');
var argv = require('optimist').default({
indx: 'test-docs',
type: 'test-doc',
warm: 10000,
docs: 100000,
sync: false,
sock: 100
})
.boolean('sync')
.argv;
function hrtime(start) {
var hr = start ? process.hrtime(start) : process.hrtime();
return start ? Math.round(((hr[0] * 1e9 + hr[1]) / 1e6) * 100) / 100 : hr;
}
var client = new es.Client({
hosts: 'localhost:9200',
log: null,
maxSockets: argv.sock
});
async.series([
function (done) {
console.log('removing existing "%s" index', argv.indx);
client.indices.delete({
index: argv.indx,
ignore: 404
}, done);
},
function (done) {
console.log('creating new "%s" index', argv.indx);
client.indices.create({
index: argv.indx,
body: {}
}, done);
},
function (done) {
console.log('warnming up index with %d docs', argv.warm);
async.times(argv.warm, function (i, done) {
client.index({
index: argv.indx,
type: argv.type,
body: {}
}, done);
}, done);
},
function (done) {
console.log('waiting for cluster to go yellow');
client.cluster.health({
waitForStatus: 'yellow'
}, done);
},
function (done) {
console.log('creating %d docs ' + (async.sync ? 'in series' : argv.sock + ' requests at a time'), argv.docs);
var start = hrtime();
async[argv.sync ? 'timesSeries' : 'times'](argv.docs, function (i, done) {
client.index({
index: argv.indx,
type: argv.type,
body: {}
}, done);
}, function (err) {
console.log('complete in', hrtime(start), 'ms');
done(err);
});
}
], function (err) {
if (err) {
console.error(err);
}
});