@@ -7,24 +7,33 @@ var client_nr = 0;
7
7
var redis = require ( '../index' ) ;
8
8
var totalTime = 0 ;
9
9
var metrics = require ( 'metrics' ) ;
10
- var num_clients = parseInt ( process . argv [ 2 ] , 10 ) || 5 ;
11
- var num_requests = 50000 ;
12
10
var tests = [ ] ;
13
11
// var bluebird = require('bluebird');
14
12
// bluebird.promisifyAll(redis.RedisClient.prototype);
15
13
// bluebird.promisifyAll(redis.Multi.prototype);
14
+
15
+ function returnArg ( name , def ) {
16
+ var matches = process . argv . filter ( function ( entry ) {
17
+ return entry . indexOf ( name + '=' ) === 0 ;
18
+ } ) ;
19
+ if ( matches . length ) {
20
+ return matches [ 0 ] . substr ( name . length + 1 ) ;
21
+ }
22
+ return def ;
23
+ }
24
+ var num_clients = returnArg ( 'clients' , 1 ) ;
25
+ var run_time = returnArg ( 'time' , 2500 ) ; // ms
16
26
var versions_logged = false ;
17
27
var client_options = {
18
28
return_buffers : false ,
19
29
max_attempts : 4 ,
20
- parser : process . argv . indexOf ( 'parser=javascript' ) === - 1 ? 'hiredis' : 'javascript'
30
+ parser : returnArg ( 'parser' , 'hiredis' )
21
31
} ;
22
32
var small_str , large_str , small_buf , large_buf , very_large_str , very_large_buf ;
23
33
24
34
function lpad ( input , len , chr ) {
25
35
var str = input . toString ( ) ;
26
36
chr = chr || ' ' ;
27
-
28
37
while ( str . length < len ) {
29
38
str = chr + str ;
30
39
}
@@ -33,33 +42,27 @@ function lpad(input, len, chr) {
33
42
34
43
metrics . Histogram . prototype . print_line = function ( ) {
35
44
var obj = this . printObj ( ) ;
36
-
37
45
return lpad ( obj . min , 4 ) + '/' + lpad ( obj . max , 4 ) + '/' + lpad ( obj . mean . toFixed ( 2 ) , 7 ) + '/' + lpad ( obj . p95 . toFixed ( 2 ) , 7 ) ;
38
46
} ;
39
47
40
48
function Test ( args ) {
41
49
this . args = args ;
42
-
43
50
this . callback = null ;
44
51
this . clients = [ ] ;
45
52
this . clients_ready = 0 ;
46
53
this . commands_sent = 0 ;
47
54
this . commands_completed = 0 ;
48
- this . max_pipeline = this . args . pipeline || num_requests ;
55
+ this . max_pipeline = this . args . pipeline || 50 ;
49
56
this . batch_pipeline = this . args . batch || 0 ;
50
57
this . client_options = args . client_options || client_options ;
51
- this . num_requests = args . reqs || num_requests ;
52
-
53
58
this . connect_latency = new metrics . Histogram ( ) ;
54
59
this . ready_latency = new metrics . Histogram ( ) ;
55
60
this . command_latency = new metrics . Histogram ( ) ;
56
61
}
57
62
58
63
Test . prototype . run = function ( callback ) {
59
64
var i ;
60
-
61
65
this . callback = callback ;
62
-
63
66
for ( i = 0 ; i < num_clients ; i ++ ) {
64
67
this . new_client ( i ) ;
65
68
}
@@ -112,27 +115,39 @@ Test.prototype.new_client = function (id) {
112
115
Test . prototype . on_clients_ready = function ( ) {
113
116
process . stdout . write ( lpad ( this . args . descr , 13 ) + ', ' + ( this . args . batch ? lpad ( 'batch ' + this . args . batch , 9 ) : lpad ( this . args . pipeline , 9 ) ) + '/' + this . clients_ready + ' ' ) ;
114
117
this . test_start = Date . now ( ) ;
115
-
116
118
this . fill_pipeline ( ) ;
117
119
} ;
118
120
119
121
Test . prototype . fill_pipeline = function ( ) {
120
122
var pipeline = this . commands_sent - this . commands_completed ;
121
123
122
- if ( this . batch_pipeline && this . commands_sent < this . num_requests ) {
124
+ if ( this . test_start < Date . now ( ) - run_time ) {
125
+ if ( this . ended ) {
126
+ return ;
127
+ }
128
+ this . ended = true ;
129
+ this . print_stats ( ) ;
130
+ this . stop_clients ( ) ;
131
+ return ;
132
+ }
133
+
134
+ if ( this . clients [ 0 ] . should_buffer ) {
135
+ var self = this ;
136
+ setTimeout ( function ( ) {
137
+ self . fill_pipeline ( ) ;
138
+ } , 1 ) ;
139
+ return ;
140
+ }
141
+
142
+ if ( this . batch_pipeline ) {
123
143
this . batch ( ) ;
124
144
} else {
125
- while ( this . commands_sent < this . num_requests && pipeline < this . max_pipeline ) {
145
+ while ( pipeline < this . max_pipeline ) {
126
146
this . commands_sent ++ ;
127
147
pipeline ++ ;
128
148
this . send_next ( ) ;
129
149
}
130
150
}
131
-
132
- if ( this . commands_completed === this . num_requests ) {
133
- this . print_stats ( ) ;
134
- this . stop_clients ( ) ;
135
- }
136
151
} ;
137
152
138
153
Test . prototype . batch = function ( ) {
@@ -191,7 +206,7 @@ Test.prototype.print_stats = function () {
191
206
totalTime += duration ;
192
207
193
208
console . log ( 'min/max/avg/p95: ' + this . command_latency . print_line ( ) + ' ' + lpad ( duration , 6 ) + 'ms total, ' +
194
- lpad ( ( this . num_requests / ( duration / 1000 ) ) . toFixed ( 2 ) , 9 ) + ' ops/sec' ) ;
209
+ lpad ( ( this . commands_completed / ( duration / 1000 ) ) . toFixed ( 2 ) , 9 ) + ' ops/sec' ) ;
195
210
} ;
196
211
197
212
small_str = '1234' ;
@@ -203,67 +218,71 @@ very_large_buf = new Buffer(very_large_str);
203
218
204
219
tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , pipeline : 1 } ) ) ;
205
220
tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , pipeline : 50 } ) ) ;
206
- tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
221
+ tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , batch : 50 } ) ) ;
207
222
208
223
tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , pipeline : 1 } ) ) ;
209
224
tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , pipeline : 50 } ) ) ;
210
- tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
225
+ tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , batch : 50 } ) ) ;
211
226
212
227
tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , pipeline : 1 } ) ) ;
213
228
tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , pipeline : 50 } ) ) ;
214
- tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
229
+ tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , batch : 50 } ) ) ;
215
230
216
231
tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 1 } ) ) ;
217
232
tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 50 } ) ) ;
218
- tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
233
+ tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , batch : 50 } ) ) ;
219
234
220
235
tests . push ( new Test ( { descr : 'GET 4B buf' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 1 , client_opts : { return_buffers : true } } ) ) ;
221
236
tests . push ( new Test ( { descr : 'GET 4B buf' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 50 , client_opts : { return_buffers : true } } ) ) ;
222
237
tests . push ( new Test ( { descr : 'GET 4B buf' , command : 'get' , args : [ 'foo_rand000000000000' ] , batch : 50 , client_opts : { return_buffers : true } } ) ) ;
223
238
224
239
tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , pipeline : 1 } ) ) ;
225
240
tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , pipeline : 50 } ) ) ;
226
- tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
241
+ tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , batch : 50 } ) ) ;
227
242
228
243
tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , pipeline : 1 } ) ) ;
229
244
tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , pipeline : 50 } ) ) ;
230
- tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
245
+ tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , batch : 50 } ) ) ;
231
246
232
247
tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 1 } ) ) ;
233
248
tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 50 } ) ) ;
234
- tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
249
+ tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , batch : 50 } ) ) ;
235
250
236
251
tests . push ( new Test ( { descr : 'GET 4KiB buf' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 1 , client_opts : { return_buffers : true } } ) ) ;
237
252
tests . push ( new Test ( { descr : 'GET 4KiB buf' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 50 , client_opts : { return_buffers : true } } ) ) ;
238
253
tests . push ( new Test ( { descr : 'GET 4KiB buf' , command : 'get' , args : [ 'foo_rand000000000001' ] , batch : 50 , client_opts : { return_buffers : true } } ) ) ;
239
254
240
255
tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , pipeline : 1 } ) ) ;
241
256
tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , pipeline : 50 } ) ) ;
242
- tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
257
+ tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , batch : 50 } ) ) ;
243
258
244
259
tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , pipeline : 1 } ) ) ;
245
260
tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , pipeline : 50 } ) ) ;
246
- tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
261
+ tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , batch : 50 } ) ) ;
247
262
248
263
tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , pipeline : 1 } ) ) ;
249
264
tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , pipeline : 50 } ) ) ;
250
- tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
265
+ tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , batch : 50 } ) ) ;
251
266
252
267
tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , pipeline : 1 } ) ) ;
253
268
tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , pipeline : 50 } ) ) ;
254
- tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , batch : 50 , reqs : num_requests * 2 } ) ) ;
269
+ tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , batch : 50 } ) ) ;
270
+
271
+ tests . push ( new Test ( { descr : 'SET 4MiB buf' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , pipeline : 1 } ) ) ;
272
+ tests . push ( new Test ( { descr : 'SET 4MiB buf' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , pipeline : 20 } ) ) ;
273
+ tests . push ( new Test ( { descr : 'SET 4MiB buf' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , batch : 20 } ) ) ;
255
274
256
- tests . push ( new Test ( { descr : 'SET 4MiB buf ' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , pipeline : 1 , reqs : 500 } ) ) ;
257
- tests . push ( new Test ( { descr : 'SET 4MiB buf ' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , pipeline : 20 , reqs : 500 } ) ) ;
258
- tests . push ( new Test ( { descr : 'SET 4MiB buf ' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , batch : 20 , reqs : 500 } ) ) ;
275
+ tests . push ( new Test ( { descr : 'SET 4MiB str ' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_str ] , pipeline : 1 } ) ) ;
276
+ tests . push ( new Test ( { descr : 'SET 4MiB str ' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_str ] , pipeline : 20 } ) ) ;
277
+ tests . push ( new Test ( { descr : 'SET 4MiB str ' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_str ] , batch : 20 } ) ) ;
259
278
260
- tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 , reqs : 100 } ) ) ;
261
- tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 20 , reqs : 100 } ) ) ;
262
- tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , batch : 20 , reqs : 100 } ) ) ;
279
+ tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 } ) ) ;
280
+ tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 20 } ) ) ;
281
+ tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , batch : 20 } ) ) ;
263
282
264
- tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 , reqs : 100 , client_opts : { return_buffers : true } } ) ) ;
265
- tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 20 , reqs : 100 , client_opts : { return_buffers : true } } ) ) ;
266
- tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , batch : 20 , reqs : 100 , client_opts : { return_buffers : true } } ) ) ;
283
+ tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 , client_opts : { return_buffers : true } } ) ) ;
284
+ tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 20 , client_opts : { return_buffers : true } } ) ) ;
285
+ tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , batch : 20 , client_opts : { return_buffers : true } } ) ) ;
267
286
268
287
function next ( ) {
269
288
var test = tests . shift ( ) ;
0 commit comments