You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Improve multi bench
It will now print the total time elapsed and start a redis server if none is running and closes it afterwards again
This commit is contained in:
@@ -1,15 +1,21 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require("../index"),
|
var path = require('path');
|
||||||
metrics = require("metrics"),
|
var RedisProcess = require("../test/lib/redis-process");
|
||||||
num_clients = parseInt(process.argv[2], 10) || 5,
|
var rp;
|
||||||
num_requests = 20000,
|
var redis = require("../index");
|
||||||
tests = [],
|
var totalTime = 0;
|
||||||
versions_logged = false,
|
var metrics = require("metrics");
|
||||||
client_options = {
|
var num_clients = parseInt(process.argv[2], 10) || 5;
|
||||||
return_buffers: false
|
var num_requests = 20000;
|
||||||
},
|
var tests = [];
|
||||||
small_str, large_str, small_buf, large_buf, very_large_str, very_large_buf;
|
var versions_logged = false;
|
||||||
|
var client_options = {
|
||||||
|
return_buffers: false,
|
||||||
|
max_attempts: 4,
|
||||||
|
parser: process.argv.indexOf('parser=javascript') === -1 ? 'hiredis' : 'javascript'
|
||||||
|
};
|
||||||
|
var small_str, large_str, small_buf, large_buf, very_large_str, very_large_buf;
|
||||||
|
|
||||||
function lpad(input, len, chr) {
|
function lpad(input, len, chr) {
|
||||||
var str = input.toString();
|
var str = input.toString();
|
||||||
@@ -57,7 +63,7 @@ Test.prototype.run = function (callback) {
|
|||||||
Test.prototype.new_client = function (id) {
|
Test.prototype.new_client = function (id) {
|
||||||
var self = this, new_client;
|
var self = this, new_client;
|
||||||
|
|
||||||
new_client = redis.createClient(6379, "127.0.0.1", this.client_options);
|
new_client = redis.createClient(this.client_options);
|
||||||
new_client.create_time = Date.now();
|
new_client.create_time = Date.now();
|
||||||
|
|
||||||
new_client.on("connect", function () {
|
new_client.on("connect", function () {
|
||||||
@@ -77,6 +83,24 @@ Test.prototype.new_client = function (id) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If no redis server is running, start one
|
||||||
|
new_client.on("error", function(err) {
|
||||||
|
if (err.code === 'CONNECTION_BROKEN') {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (rp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rp = true;
|
||||||
|
var conf = '../test/conf/redis.conf';
|
||||||
|
RedisProcess.start(function (err, _rp) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
rp = _rp;
|
||||||
|
}, path.resolve(__dirname, conf));
|
||||||
|
});
|
||||||
|
|
||||||
self.clients[id] = new_client;
|
self.clients[id] = new_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -133,6 +157,7 @@ Test.prototype.send_next = function () {
|
|||||||
|
|
||||||
Test.prototype.print_stats = function () {
|
Test.prototype.print_stats = function () {
|
||||||
var duration = Date.now() - this.test_start;
|
var duration = Date.now() - this.test_start;
|
||||||
|
totalTime += duration;
|
||||||
|
|
||||||
console.log("min/max/avg/p95: " + this.command_latency.print_line() + " " + lpad(duration, 6) + "ms total, " +
|
console.log("min/max/avg/p95: " + this.command_latency.print_line() + " " + lpad(duration, 6) + "ms total, " +
|
||||||
lpad((this.num_requests / (duration / 1000)).toFixed(2), 8) + " ops/sec");
|
lpad((this.num_requests / (duration / 1000)).toFixed(2), 8) + " ops/sec");
|
||||||
@@ -199,8 +224,14 @@ function next() {
|
|||||||
test.run(function () {
|
test.run(function () {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
} else if (rp) {
|
||||||
|
// Stop the redis process if started by the benchmark
|
||||||
|
rp.stop(function() {
|
||||||
|
rp = undefined;
|
||||||
|
next();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("End of tests.");
|
console.log("End of tests. Total time elapsed:", totalTime, 'ms');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user