You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Improvements to recreate redis-benchmark.
This commit is contained in:
133
multi_bench.js
133
multi_bench.js
@@ -1,20 +1,14 @@
|
||||
/*global require console setTimeout process */
|
||||
|
||||
var redis = require("./index"),
|
||||
client_count = 10000,
|
||||
tests_per_client = 100,
|
||||
clients = new Array(client_count), i, tests = {}, results = {}, test_list;
|
||||
request = require("request"),
|
||||
stats_url = "mjr.couchone.com/bench",
|
||||
client_count = 50,
|
||||
ops_count = 10000,
|
||||
clients = new Array(client_count),
|
||||
i, tests = {}, results = {}, test_list;
|
||||
|
||||
function get_result(name, index) {
|
||||
results[name].starts[index] = new Date();
|
||||
return function (err, reply) {
|
||||
results[name].ends[index] = new Date();
|
||||
results[name].completed += 1;
|
||||
if (results[name].completed === client_count) {
|
||||
test_complete(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
redis.debug_mode = false;
|
||||
|
||||
function init_test(name) {
|
||||
results[name] = {
|
||||
@@ -41,6 +35,9 @@ function test_complete(name) {
|
||||
|
||||
for (i = 0, len = results[name].ends.length; i < len; i += 1) {
|
||||
sample = results[name].ends[i] - results[name].starts[i];
|
||||
if (isNaN(sample)) {
|
||||
console.log("NaN: " + i + ", " + results[name].ends[i] + ", " + results[name].starts[i]);
|
||||
}
|
||||
sum += sample;
|
||||
if (sample < min) {
|
||||
min = sample;
|
||||
@@ -57,7 +54,7 @@ function test_complete(name) {
|
||||
}
|
||||
}
|
||||
|
||||
avg = (sum / client_count).toFixed(2);
|
||||
avg = (sum / ops_count).toFixed(2);
|
||||
op_rate = ((i + 1) / (total_time/1000)).toFixed(2);
|
||||
|
||||
console.log(name + ": " + i + " ops " + op_rate + " ops/sec " + min + "/" + max + "/" + avg);
|
||||
@@ -70,21 +67,46 @@ function test_complete(name) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object.keys(buckets).forEach(function (bucket) {
|
||||
var bar = "", i, max_width = 100, cur_val = buckets[bucket];
|
||||
|
||||
i = Math.round((cur_val / max_bucket) * max_width);
|
||||
|
||||
while (i >= 0) {
|
||||
bar += "*";
|
||||
i--;
|
||||
}
|
||||
console.log(lpad(bucket) + ": " + bar);
|
||||
});
|
||||
// Object.keys(buckets).forEach(function (bucket) {
|
||||
// var bar = "", i, max_width = 100, cur_val = buckets[bucket];
|
||||
//
|
||||
// i = Math.round((cur_val / max_bucket) * max_width);
|
||||
//
|
||||
// while (i >= 0) {
|
||||
// bar += "*";
|
||||
// i--;
|
||||
// }
|
||||
// console.log(lpad(bucket) + ": " + bar);
|
||||
// });
|
||||
|
||||
run_next();
|
||||
}
|
||||
|
||||
function get_result(name, index) {
|
||||
results[name].starts[index] = new Date();
|
||||
return function (err, reply) {
|
||||
results[name].ends[index] = new Date();
|
||||
results[name].completed += 1;
|
||||
if (results[name].completed === ops_count) {
|
||||
test_complete(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function spread_command(name, command, args) {
|
||||
var remaining = ops_count - 1,
|
||||
current = 0;
|
||||
|
||||
while (remaining >= 0) {
|
||||
clients[current][command](args, get_result(name, remaining));
|
||||
current += 1;
|
||||
if (current >= client_count) {
|
||||
current = 0;
|
||||
}
|
||||
remaining -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
tests.connections = function () {
|
||||
var name = "connections";
|
||||
|
||||
@@ -99,7 +121,7 @@ tests.connections = function () {
|
||||
function start_connection (num) {
|
||||
results[name].starts[num] = new Date();
|
||||
clients[num] = redis.createClient();
|
||||
if (num < (client_count - 1)) {
|
||||
if (num < client_count) {
|
||||
clients[num].on("connect", handle_connection(num));
|
||||
} else {
|
||||
clients[num].on("connect", function () {
|
||||
@@ -117,20 +139,73 @@ tests.connections = function () {
|
||||
start_connection(0);
|
||||
};
|
||||
|
||||
tests.set = function () {
|
||||
tests.ping = function () {
|
||||
var name = "PING (multi bulk)";
|
||||
|
||||
init_test(name);
|
||||
spread_command(name, "ping", []);
|
||||
};
|
||||
|
||||
tests.set = function () {
|
||||
var name = "SET";
|
||||
|
||||
init_test(name);
|
||||
spread_command(name, "set", ["foo_rand000000000000", ops_count]);
|
||||
};
|
||||
|
||||
tests.get = function () {
|
||||
var name = "GET";
|
||||
|
||||
init_test(name);
|
||||
spread_command(name, "get", ["foo_rand000000000000"]);
|
||||
};
|
||||
|
||||
tests.incr = function () {
|
||||
var name = "incr";
|
||||
|
||||
init_test(name);
|
||||
spread_command(name, "incr", ["counter_rand000000000000"]);
|
||||
};
|
||||
|
||||
tests.lpush = function () {
|
||||
var name = "lpush";
|
||||
|
||||
init_test(name);
|
||||
spread_command(name, "lpush", ["mylist", "bar"]);
|
||||
};
|
||||
|
||||
tests.lpop = function () {
|
||||
var name = "lpop";
|
||||
|
||||
init_test(name);
|
||||
spread_command(name, "lpop", ["mylist"]);
|
||||
};
|
||||
|
||||
tests.sadd = function () {
|
||||
var name = "sadd";
|
||||
|
||||
init_test(name);
|
||||
spread_command(name, "sadd", ["myset", "counter_rand000000000000"]);
|
||||
};
|
||||
|
||||
// need to randomize the counter
|
||||
|
||||
// tests.spop = function () {
|
||||
// var name = "lpop";
|
||||
//
|
||||
// init_test(name);
|
||||
// spread_command(name, "lpop", ["mylist"]);
|
||||
// };
|
||||
|
||||
|
||||
test_list = Object.keys(tests);
|
||||
|
||||
function run_next() {
|
||||
var cur_test = test_list.shift();
|
||||
if (typeof tests[cur_test] === "function") {
|
||||
console.log("Starting " + cur_test);
|
||||
tests[cur_test]();
|
||||
} else {
|
||||
console.log("End of tests.");
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user