This repository has been archived by the owner on Nov 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
bench.js
121 lines (108 loc) · 2.64 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var hiredis = require("./hiredis"),
num_clients = 10,
active_clients = 0,
pipeline = 0,
num_requests = parseInt(process.argv[2]) || 20000,
issued_requests = 0,
test_start;
var tests = [];
tests.push({
descr: "PING",
command: ["PING"]
});
tests.push({
descr: "SET",
command: ["SET", "foo", "bar"]
});
tests.push({
descr: "GET",
command: ["GET", "foo"]
});
tests.push({
descr: "LPUSH 8 bytes",
command: ["LPUSH", "mylist-8", new Buffer(Array(8).join("-"))]
});
tests.push({
descr: "LPUSH 64 bytes",
command: ["LPUSH", "mylist-64", new Buffer(Array(64).join("-"))]
});
tests.push({
descr: "LPUSH 512 bytes",
command: ["LPUSH", "mylist-512", new Buffer(Array(512).join("-"))]
});
tests.push({
descr: "LRANGE 10 elements, 8 bytes",
command: ["LRANGE", "mylist-8", "0", "9"]
});
tests.push({
descr: "LRANGE 100 elements, 8 bytes",
command: ["LRANGE", "mylist-8", "0", "99"]
});
tests.push({
descr: "LRANGE 100 elements, 64 bytes",
command: ["LRANGE", "mylist-64", "0", "99"]
});
tests.push({
descr: "LRANGE 100 elements, 512 bytes",
command: ["LRANGE", "mylist-512", "0", "99"]
});
function call(client, test) {
client.on("reply", function() {
if (issued_requests < num_requests) {
request();
} else {
client.end();
if (--active_clients == 0)
done(test);
}
});
function request() {
issued_requests++;
client.write.apply(client,test.command);
};
request();
}
function done(test) {
var time = (new Date - test_start);
var op_rate = (num_requests/(time/1000.0)).toFixed(2);
console.log(test.descr + ": " + op_rate + " ops/sec");
next();
}
function concurrent_test(test) {
var i = num_clients;
var client;
issued_requests = 0;
test_start = new Date;
while(i-- && issued_requests < num_requests) {
active_clients++;
client = hiredis.createConnection();
call(client, test);
}
}
function pipelined_test(test) {
var client = hiredis.createConnection();
var received_replies = 0;
issued_requests = 0;
while (issued_requests < num_requests) {
issued_requests++;
client.write.apply(client,test.command);
}
test_start = new Date;
client.on("reply", function() {
if (++received_replies == num_requests) {
client.end();
done(test);
}
});
}
function next() {
var test = tests.shift();
if (test) {
if (pipeline) {
pipelined_test(test);
} else {
concurrent_test(test);
}
}
}
next();