You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Set up connections serially.
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
/*global require console setTimeout process */
|
/*global require console setTimeout process */
|
||||||
|
|
||||||
var redis = require("./index"),
|
var redis = require("./index"),
|
||||||
client_count = 500,
|
client_count = 10000,
|
||||||
|
tests_per_client = 100,
|
||||||
clients = new Array(client_count), i, tests = {}, results = {}, test_list;
|
clients = new Array(client_count), i, tests = {}, results = {}, test_list;
|
||||||
|
|
||||||
function get_result(name, index) {
|
function get_result(name, index) {
|
||||||
|
results[name].starts[index] = new Date();
|
||||||
return function (err, reply) {
|
return function (err, reply) {
|
||||||
results[name].samples[index] = new Date();
|
results[name].ends[index] = new Date();
|
||||||
results[name].completed += 1;
|
results[name].completed += 1;
|
||||||
if (results[name].completed === client_count) {
|
if (results[name].completed === client_count) {
|
||||||
test_complete(name);
|
test_complete(name);
|
||||||
@@ -16,23 +18,29 @@ function get_result(name, index) {
|
|||||||
|
|
||||||
function init_test(name) {
|
function init_test(name) {
|
||||||
results[name] = {
|
results[name] = {
|
||||||
start: new Date(),
|
test_start: new Date(),
|
||||||
samples: new Array(client_count),
|
starts: new Array(client_count),
|
||||||
|
ends: new Array(client_count),
|
||||||
completed: 0
|
completed: 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_complete(name) {
|
function test_complete(name) {
|
||||||
var min, max, sum, avg, res;
|
var min, max, sum, avg, res, i, sample, total_time, op_rate, buckets = {}, max_bucket;
|
||||||
|
|
||||||
|
results[name].test_end = new Date();
|
||||||
|
|
||||||
|
total_time = results[name].test_end - results[name].test_start;
|
||||||
|
|
||||||
res = results[name];
|
res = results[name];
|
||||||
|
|
||||||
min = res.samples[0] - res.start;
|
max_bucket = Number.MIN_VALUE;
|
||||||
max = res.samples[0] - res.start;
|
min = Number.MAX_VALUE;
|
||||||
|
max = Number.MIN_VALUE;
|
||||||
sum = 0;
|
sum = 0;
|
||||||
|
|
||||||
results[name].samples.forEach(function (sample, index) {
|
for (i = 0, len = results[name].ends.length; i < len; i += 1) {
|
||||||
sample -= res.start;
|
sample = results[name].ends[i] - results[name].starts[i];
|
||||||
sum += sample;
|
sum += sample;
|
||||||
if (sample < min) {
|
if (sample < min) {
|
||||||
min = sample;
|
min = sample;
|
||||||
@@ -40,25 +48,77 @@ function test_complete(name) {
|
|||||||
if (sample > max) {
|
if (sample > max) {
|
||||||
max = sample;
|
max = sample;
|
||||||
}
|
}
|
||||||
});
|
if (buckets[sample] === undefined) {
|
||||||
|
buckets[sample] = 0;
|
||||||
|
}
|
||||||
|
buckets[sample] += 1;
|
||||||
|
if (buckets[sample] > max_bucket) {
|
||||||
|
max_bucket = buckets[sample];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
avg = (sum / client_count).toFixed(2);
|
avg = (sum / client_count).toFixed(2);
|
||||||
|
op_rate = ((i + 1) / (total_time/1000)).toFixed(2);
|
||||||
|
|
||||||
console.log(name + ": " + min + "/" + max + "/" + avg);
|
console.log(name + ": " + i + " ops " + op_rate + " ops/sec " + min + "/" + max + "/" + avg);
|
||||||
|
|
||||||
|
function lpad(val) {
|
||||||
|
var ret = val.toString();
|
||||||
|
while (ret.length < max_bucket.toString().length) {
|
||||||
|
ret = " " + ret;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
run_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
tests.connections = function () {
|
tests.connections = function () {
|
||||||
var name = "connections";
|
var name = "connections";
|
||||||
|
|
||||||
init_test(name);
|
|
||||||
|
|
||||||
for (i = 0; i < client_count ; i += 1) {
|
function handle_connection (num) {
|
||||||
clients[i] = redis.createClient();
|
return function () {
|
||||||
clients[i].on("connect", get_result("connections", i));
|
results[name].ends[num] = new Date();
|
||||||
clients[i].on("error", function (msg) {
|
results[name].completed += 1;
|
||||||
console.log("Connect problem: " + msg);
|
start_connection(num + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function start_connection (num) {
|
||||||
|
results[name].starts[num] = new Date();
|
||||||
|
clients[num] = redis.createClient();
|
||||||
|
if (num < (client_count - 1)) {
|
||||||
|
clients[num].on("connect", handle_connection(num));
|
||||||
|
} else {
|
||||||
|
clients[num].on("connect", function () {
|
||||||
|
results[name].ends[num] = new Date();
|
||||||
|
results[name].completed += 1;
|
||||||
|
test_complete(name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
clients[num].on("error", function (msg) {
|
||||||
|
console.log("Connect problem:" + msg.stack);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_test(name);
|
||||||
|
start_connection(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
tests.set = function () {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
test_list = Object.keys(tests);
|
test_list = Object.keys(tests);
|
||||||
@@ -70,7 +130,9 @@ function run_next() {
|
|||||||
tests[cur_test]();
|
tests[cur_test]();
|
||||||
} else {
|
} else {
|
||||||
console.log("End of tests.");
|
console.log("End of tests.");
|
||||||
|
process.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
run_next();
|
run_next();
|
||||||
|
Reference in New Issue
Block a user