33var path = require ( 'path' ) ;
44var RedisProcess = require ( '../test/lib/redis-process' ) ;
55var rp ;
6+ var client_nr = 0 ;
67var redis = require ( '../index' ) ;
78var totalTime = 0 ;
89var metrics = require ( 'metrics' ) ;
@@ -42,6 +43,7 @@ function Test(args) {
4243 this . commands_sent = 0 ;
4344 this . commands_completed = 0 ;
4445 this . max_pipeline = this . args . pipeline || num_requests ;
46+ this . batch_pipeline = this . args . batch || 0 ;
4547 this . client_options = args . client_options || client_options ;
4648 this . num_requests = args . reqs || num_requests ;
4749
@@ -105,7 +107,7 @@ Test.prototype.new_client = function (id) {
105107} ;
106108
107109Test . 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 + ' ' ) ;
109111 this . test_start = Date . now ( ) ;
110112
111113 this . fill_pipeline ( ) ;
@@ -114,10 +116,14 @@ Test.prototype.on_clients_ready = function () {
114116Test . prototype . fill_pipeline = function ( ) {
115117 var pipeline = this . commands_sent - this . commands_completed ;
116118
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+ }
121127 }
122128
123129 if ( this . commands_completed === this . num_requests ) {
@@ -126,6 +132,28 @@ Test.prototype.fill_pipeline = function () {
126132 }
127133} ;
128134
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+
129157Test . prototype . stop_clients = function ( ) {
130158 var self = this ;
131159
@@ -160,7 +188,7 @@ Test.prototype.print_stats = function () {
160188 totalTime += duration ;
161189
162190 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' ) ;
164192} ;
165193
166194small_str = '1234' ;
@@ -172,51 +200,67 @@ very_large_buf = new Buffer(very_large_str);
172200
173201tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , pipeline : 1 } ) ) ;
174202tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , pipeline : 50 } ) ) ;
203+ tests . push ( new Test ( { descr : 'PING' , command : 'ping' , args : [ ] , batch : 50 } ) ) ;
175204
176205tests . push ( new Test ( { descr : 'SET 4B str' , command : 'set' , args : [ 'foo_rand000000000000' , small_str ] , pipeline : 1 } ) ) ;
177206tests . 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 } ) ) ;
178208
179209tests . push ( new Test ( { descr : 'SET 4B buf' , command : 'set' , args : [ 'foo_rand000000000000' , small_buf ] , pipeline : 1 } ) ) ;
180210tests . 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 } ) ) ;
181212
182213tests . push ( new Test ( { descr : 'GET 4B str' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 1 } ) ) ;
183214tests . 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 } ) ) ;
184216
185217tests . push ( new Test ( { descr : 'GET 4B buf' , command : 'get' , args : [ 'foo_rand000000000000' ] , pipeline : 1 , client_opts : { return_buffers : true } } ) ) ;
186218tests . 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 } } ) ) ;
187220
188221tests . push ( new Test ( { descr : 'SET 4KiB str' , command : 'set' , args : [ 'foo_rand000000000001' , large_str ] , pipeline : 1 } ) ) ;
189222tests . 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 } ) ) ;
190224
191225tests . push ( new Test ( { descr : 'SET 4KiB buf' , command : 'set' , args : [ 'foo_rand000000000001' , large_buf ] , pipeline : 1 } ) ) ;
192226tests . 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 } ) ) ;
193228
194229tests . push ( new Test ( { descr : 'GET 4KiB str' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 1 } ) ) ;
195230tests . 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 } ) ) ;
196232
197233tests . push ( new Test ( { descr : 'GET 4KiB buf' , command : 'get' , args : [ 'foo_rand000000000001' ] , pipeline : 1 , client_opts : { return_buffers : true } } ) ) ;
198234tests . 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 } } ) ) ;
199236
200237tests . push ( new Test ( { descr : 'INCR' , command : 'incr' , args : [ 'counter_rand000000000000' ] , pipeline : 1 } ) ) ;
201238tests . 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 } ) ) ;
202240
203241tests . push ( new Test ( { descr : 'LPUSH' , command : 'lpush' , args : [ 'mylist' , small_str ] , pipeline : 1 } ) ) ;
204242tests . 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 } ) ) ;
205244
206245tests . push ( new Test ( { descr : 'LRANGE 10' , command : 'lrange' , args : [ 'mylist' , '0' , '9' ] , pipeline : 1 } ) ) ;
207246tests . 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 } ) ) ;
208248
209249tests . push ( new Test ( { descr : 'LRANGE 100' , command : 'lrange' , args : [ 'mylist' , '0' , '99' ] , pipeline : 1 } ) ) ;
210250tests . 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 } ) ) ;
211252
212253tests . push ( new Test ( { descr : 'SET 4MiB buf' , command : 'set' , args : [ 'foo_rand000000000002' , very_large_buf ] , pipeline : 1 , reqs : 500 } ) ) ;
213254tests . 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 } ) ) ;
214256
215257tests . push ( new Test ( { descr : 'GET 4MiB str' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 , reqs : 100 } ) ) ;
216258tests . 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 } ) ) ;
217260
218261tests . push ( new Test ( { descr : 'GET 4MiB buf' , command : 'get' , args : [ 'foo_rand000000000002' ] , pipeline : 1 , reqs : 100 , client_opts : { return_buffers : true } } ) ) ;
219262tests . 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 } } ) ) ;
220264
221265function next ( ) {
222266 var test = tests . shift ( ) ;
0 commit comments