3
3
var path = require ( 'path' ) ;
4
4
var RedisProcess = require ( '../test/lib/redis-process' ) ;
5
5
var rp ;
6
+ var client_nr = 0 ;
6
7
var redis = require ( '../index' ) ;
7
8
var totalTime = 0 ;
8
9
var metrics = require ( 'metrics' ) ;
@@ -42,6 +43,7 @@ function Test(args) {
42
43
this . commands_sent = 0 ;
43
44
this . commands_completed = 0 ;
44
45
this . max_pipeline = this . args . pipeline || num_requests ;
46
+ this . batch_pipeline = this . args . batch || 0 ;
45
47
this . client_options = args . client_options || client_options ;
46
48
this . num_requests = args . reqs || num_requests ;
47
49
@@ -105,7 +107,7 @@ Test.prototype.new_client = function (id) {
105
107
} ;
106
108
107
109
Test . prototype . on_clients_ready = function ( ) {
108
- process . stdout . write ( lpad ( this . args . descr , 13 ) + ', ' + lpad ( this . args . pipeline , 5 ) + '/' + this . clients_ready + ' ' ) ;
110
+ 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 + ' ' ) ;
109
111
this . test_start = Date . now ( ) ;
110
112
111
113
this . fill_pipeline ( ) ;
@@ -114,10 +116,14 @@ Test.prototype.on_clients_ready = function () {
114
116
Test . prototype . fill_pipeline = function ( ) {
115
117
var pipeline = this . commands_sent - this . commands_completed ;
116
118
117
- while ( this . commands_sent < this . num_requests && pipeline < this . max_pipeline ) {
118
- this . commands_sent ++ ;
119
- pipeline ++ ;
120
- this . send_next ( ) ;
119
+ if ( this . batch_pipeline && this . commands_sent < this . num_requests ) {
120
+ this . batch ( ) ;
121
+ } else {
122
+ while ( this . commands_sent < this . num_requests && pipeline < this . max_pipeline ) {
123
+ this . commands_sent ++ ;
124
+ pipeline ++ ;
125
+ this . send_next ( ) ;
126
+ }
121
127
}
122
128
123
129
if ( this . commands_completed === this . num_requests ) {
@@ -126,6 +132,28 @@ Test.prototype.fill_pipeline = function () {
126
132
}
127
133
} ;
128
134
135
+ Test . prototype . batch = function ( ) {
136
+ var self = this ,
137
+ cur_client = client_nr ++ % this . clients . length ,
138
+ start = Date . now ( ) ,
139
+ i = 0 ,
140
+ batch = this . clients [ cur_client ] . batch ( ) ;
141
+
142
+ while ( i ++ < this . batch_pipeline ) {
143
+ this . commands_sent ++ ;
144
+ batch [ this . args . command ] ( this . args . args ) ;
145
+ }
146
+
147
+ batch . exec ( function ( err , res ) {
148
+ if ( err ) {
149
+ throw err ;
150
+ }
151
+ self . commands_completed += res . length ;
152
+ self . command_latency . update ( Date . now ( ) - start ) ;
153
+ self . fill_pipeline ( ) ;
154
+ } ) ;
155
+ } ;
156
+
129
157
Test . prototype . stop_clients = function ( ) {
130
158
var self = this ;
131
159
@@ -160,7 +188,7 @@ Test.prototype.print_stats = function () {
160
188
totalTime += duration ;
161
189
162
190
console . log ( 'min/max/avg/p95: ' + this . command_latency . print_line ( ) + ' ' + lpad ( duration , 6 ) + 'ms total, ' +
163
- lpad ( ( this . num_requests / ( duration / 1000 ) ) . toFixed ( 2 ) , 8 ) + ' ops/sec' ) ;
191
+ lpad ( ( this . num_requests / ( duration / 1000 ) ) . toFixed ( 2 ) , 9 ) + ' ops/sec' ) ;
164
192
} ;
165
193
166
194
small_str = '1234' ;
@@ -172,51 +200,67 @@ very_large_buf = new Buffer(very_large_str);
172
200
173
201
tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , pipeline : 1 } ) ) ;
174
202
tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , pipeline : 50 } ) ) ;
203
+ tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , batch : 50 } ) ) ;
175
204
176
205
tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , pipeline : 1 } ) ) ;
177
206
tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , pipeline : 50 } ) ) ;
207
+ tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , batch : 50 } ) ) ;
178
208
179
209
tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , pipeline : 1 } ) ) ;
180
210
tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , pipeline : 50 } ) ) ;
211
+ tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , batch : 50 } ) ) ;
181
212
182
213
tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 1 } ) ) ;
183
214
tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 50 } ) ) ;
215
+ tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , batch : 50 } ) ) ;
184
216
185
217
tests . push ( new Test ( { descr : 'GET 4B buf' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 1 , client_opts : { return_buffers : true } } ) ) ;
186
218
tests . push ( new Test ( { descr : 'GET 4B buf' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 50 , client_opts : { return_buffers : true } } ) ) ;
219
+ tests . push ( new Test ( { descr : 'GET 4B buf' , command : 'get' , args : [ 'foo_rand000000000000' ] , batch : 50 , client_opts : { return_buffers : true } } ) ) ;
187
220
188
221
tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , pipeline : 1 } ) ) ;
189
222
tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , pipeline : 50 } ) ) ;
223
+ tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , batch : 50 } ) ) ;
190
224
191
225
tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , pipeline : 1 } ) ) ;
192
226
tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , pipeline : 50 } ) ) ;
227
+ tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , batch : 50 } ) ) ;
193
228
194
229
tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 1 } ) ) ;
195
230
tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 50 } ) ) ;
231
+ tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , batch : 50 } ) ) ;
196
232
197
233
tests . push ( new Test ( { descr : 'GET 4KiB buf' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 1 , client_opts : { return_buffers : true } } ) ) ;
198
234
tests . push ( new Test ( { descr : 'GET 4KiB buf' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 50 , client_opts : { return_buffers : true } } ) ) ;
235
+ tests . push ( new Test ( { descr : 'GET 4KiB buf' , command : 'get' , args : [ 'foo_rand000000000001' ] , batch : 50 , client_opts : { return_buffers : true } } ) ) ;
199
236
200
237
tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , pipeline : 1 } ) ) ;
201
238
tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , pipeline : 50 } ) ) ;
239
+ tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , batch : 50 } ) ) ;
202
240
203
241
tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , pipeline : 1 } ) ) ;
204
242
tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , pipeline : 50 } ) ) ;
243
+ tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , batch : 50 } ) ) ;
205
244
206
245
tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , pipeline : 1 } ) ) ;
207
246
tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , pipeline : 50 } ) ) ;
247
+ tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , batch : 50 } ) ) ;
208
248
209
249
tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , pipeline : 1 } ) ) ;
210
250
tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , pipeline : 50 } ) ) ;
251
+ tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , batch : 50 } ) ) ;
211
252
212
253
tests . push ( new Test ( { descr : 'SET 4MiB buf' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , pipeline : 1 , reqs : 500 } ) ) ;
213
254
tests . push ( new Test ( { descr : 'SET 4MiB buf' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , pipeline : 50 , reqs : 500 } ) ) ;
255
+ tests . push ( new Test ( { descr : 'SET 4MiB buf' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , batch : 50 , reqs : 500 } ) ) ;
214
256
215
257
tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 , reqs : 100 } ) ) ;
216
258
tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 50 , reqs : 100 } ) ) ;
259
+ tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , batch : 50 , reqs : 100 } ) ) ;
217
260
218
261
tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 , reqs : 100 , client_opts : { return_buffers : true } } ) ) ;
219
262
tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 50 , reqs : 100 , client_opts : { return_buffers : true } } ) ) ;
263
+ tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , batch : 50 , reqs : 100 , client_opts : { return_buffers : true } } ) ) ;
220
264
221
265
function next ( ) {
222
266
var test = tests . shift ( ) ;
0 commit comments