]> git.saurik.com Git - redis.git/blame - src/redis-benchmark.c
Refactor reply parsing code in redis-benchmark for efficiency
[redis.git] / src / redis-benchmark.c
CommitLineData
ed9b544e 1/* Redis benchmark utility.
2 *
12d090d2 3 * Copyright (c) 2009-2010, Salvatore Sanfilippo <antirez at gmail dot com>
ed9b544e 4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of Redis nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without
16 * specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
5f5b9840 31#include "fmacros.h"
32
ed9b544e 33#include <stdio.h>
34#include <string.h>
35#include <stdlib.h>
36#include <unistd.h>
37#include <errno.h>
38#include <sys/time.h>
39#include <signal.h>
40#include <assert.h>
41
42#include "ae.h"
43#include "anet.h"
44#include "sds.h"
45#include "adlist.h"
46#include "zmalloc.h"
47
48#define REPLY_INT 0
49#define REPLY_RETCODE 1
50#define REPLY_BULK 2
6c4e61b3 51#define REPLY_MBULK 3
ed9b544e 52
53#define CLIENT_CONNECTING 0
54#define CLIENT_SENDQUERY 1
55#define CLIENT_READREPLY 2
56
57#define MAX_LATENCY 5000
58
59#define REDIS_NOTUSED(V) ((void) V)
60
61static struct config {
58cd7103 62 int debug;
ed9b544e 63 int numclients;
64 int requests;
65 int liveclients;
66 int donerequests;
67 int keysize;
68 int datasize;
57172ffb 69 int randomkeys;
ecfaf6da 70 int randomkeys_keyspacelen;
ed9b544e 71 aeEventLoop *el;
72 char *hostip;
73 int hostport;
74 int keepalive;
75 long long start;
76 long long totlatency;
77 int *latency;
78 list *clients;
79 int quiet;
80 int loop;
266373b2 81 int idlemode;
ed9b544e 82} config;
83
84typedef struct _client {
85 int state;
86 int fd;
87 sds obuf;
88 sds ibuf;
2fd30952 89 int mbulk; /* Number of elements in an mbulk reply */
ed9b544e 90 int readlen; /* readlen == -1 means read a single line */
58cd7103 91 int totreceived;
ed9b544e 92 unsigned int written; /* bytes of 'obuf' already written */
93 int replytype;
94 long long start; /* start time in milliseconds */
95} *client;
96
97/* Prototypes */
98static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask);
99static void createMissingClients(client c);
100
101/* Implementation */
102static long long mstime(void) {
103 struct timeval tv;
104 long long mst;
105
106 gettimeofday(&tv, NULL);
107 mst = ((long)tv.tv_sec)*1000;
108 mst += tv.tv_usec/1000;
109 return mst;
110}
111
112static void freeClient(client c) {
113 listNode *ln;
114
115 aeDeleteFileEvent(config.el,c->fd,AE_WRITABLE);
116 aeDeleteFileEvent(config.el,c->fd,AE_READABLE);
117 sdsfree(c->ibuf);
118 sdsfree(c->obuf);
119 close(c->fd);
120 zfree(c);
121 config.liveclients--;
122 ln = listSearchKey(config.clients,c);
123 assert(ln != NULL);
124 listDelNode(config.clients,ln);
125}
126
127static void freeAllClients(void) {
128 listNode *ln = config.clients->head, *next;
129
130 while(ln) {
131 next = ln->next;
132 freeClient(ln->value);
133 ln = next;
134 }
135}
136
137static void resetClient(client c) {
138 aeDeleteFileEvent(config.el,c->fd,AE_WRITABLE);
139 aeDeleteFileEvent(config.el,c->fd,AE_READABLE);
266373b2 140 aeCreateFileEvent(config.el,c->fd, AE_WRITABLE,writeHandler,c);
ed9b544e 141 sdsfree(c->ibuf);
142 c->ibuf = sdsempty();
89ee361e 143 c->readlen = (c->replytype == REPLY_BULK ||
144 c->replytype == REPLY_MBULK) ? -1 : 0;
2fd30952 145 c->mbulk = -1;
ed9b544e 146 c->written = 0;
58cd7103 147 c->totreceived = 0;
ed9b544e 148 c->state = CLIENT_SENDQUERY;
149 c->start = mstime();
74077975 150 createMissingClients(c);
ed9b544e 151}
152
ecfaf6da 153static void randomizeClientKey(client c) {
154 char *p;
155 char buf[32];
156 long r;
157
158 p = strstr(c->obuf, "_rand");
159 if (!p) return;
160 p += 5;
161 r = random() % config.randomkeys_keyspacelen;
162 sprintf(buf,"%ld",r);
163 memcpy(p,buf,strlen(buf));
164}
165
2fd30952 166static void prepareClientForReply(client c, int type) {
167 if (type == REPLY_BULK) {
168 c->replytype = REPLY_BULK;
169 c->readlen = -1;
170 } else if (type == REPLY_MBULK) {
171 c->replytype = REPLY_MBULK;
172 c->readlen = -1;
173 c->mbulk = -1;
174 } else {
175 c->replytype = type;
176 c->readlen = 0;
177 }
178}
179
ed9b544e 180static void clientDone(client c) {
58cd7103 181 static int last_tot_received = 1;
182
ed9b544e 183 long long latency;
184 config.donerequests ++;
185 latency = mstime() - c->start;
186 if (latency > MAX_LATENCY) latency = MAX_LATENCY;
187 config.latency[latency]++;
188
58cd7103 189 if (config.debug && last_tot_received != c->totreceived) {
190 printf("Tot bytes received: %d\n", c->totreceived);
191 last_tot_received = c->totreceived;
192 }
ed9b544e 193 if (config.donerequests == config.requests) {
194 freeClient(c);
195 aeStop(config.el);
196 return;
197 }
198 if (config.keepalive) {
199 resetClient(c);
ecfaf6da 200 if (config.randomkeys) randomizeClientKey(c);
ed9b544e 201 } else {
202 config.liveclients--;
203 createMissingClients(c);
204 config.liveclients++;
205 freeClient(c);
206 }
207}
208
36babc1e
PN
209/* Read a length from the buffer pointed to by *p, store the length in *len,
210 * and return the number of bytes that the cursor advanced. */
211static int readLen(char *p, int *len) {
212 char *tail = strstr(p,"\r\n");
213 if (tail == NULL)
214 return 0;
215 *tail = '\0';
216 *len = atoi(p+1);
217 return tail+2-p;
218}
219
ed9b544e 220static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask)
221{
36babc1e
PN
222 char buf[1024], *p;
223 int nread, pos=0, len=0;
ed9b544e 224 client c = privdata;
225 REDIS_NOTUSED(el);
226 REDIS_NOTUSED(fd);
227 REDIS_NOTUSED(mask);
228
36babc1e 229 nread = read(c->fd,buf,sizeof(buf));
ed9b544e 230 if (nread == -1) {
231 fprintf(stderr, "Reading from socket: %s\n", strerror(errno));
232 freeClient(c);
233 return;
234 }
235 if (nread == 0) {
236 fprintf(stderr, "EOF from client\n");
237 freeClient(c);
238 return;
239 }
58cd7103 240 c->totreceived += nread;
ed9b544e 241 c->ibuf = sdscatlen(c->ibuf,buf,nread);
36babc1e 242 len = sdslen(c->ibuf);
ed9b544e 243
244 if (c->replytype == REPLY_INT ||
36babc1e
PN
245 c->replytype == REPLY_RETCODE)
246 {
247 /* Check if the first line is complete. This is everything we need
248 * when waiting for an integer or status code reply.*/
249 if ((p = strstr(c->ibuf,"\r\n")) != NULL)
250 goto done;
251 } else if (c->replytype == REPLY_BULK) {
252 int advance = 0;
253 if (c->readlen < 0) {
254 advance = readLen(c->ibuf+pos,&c->readlen);
255 if (advance) {
256 pos += advance;
257 if (c->readlen == -1) {
258 goto done;
259 } else {
260 /* include the trailing \r\n */
261 c->readlen += 2;
2fd30952 262 }
ed9b544e 263 } else {
36babc1e 264 goto skip;
ed9b544e 265 }
266 }
36babc1e
PN
267
268 int canconsume;
269 if (c->readlen > 0) {
270 canconsume = c->readlen > (len-pos) ? (len-pos) : c->readlen;
271 c->readlen -= canconsume;
272 pos += canconsume;
273 }
274
275 if (c->readlen == 0)
276 goto done;
277 } else if (c->replytype == REPLY_MBULK) {
278 int advance = 0;
279 if (c->mbulk == -1) {
280 advance = readLen(c->ibuf+pos,&c->mbulk);
281 if (advance) {
282 pos += advance;
283 if (c->mbulk == -1)
284 goto done;
285 } else {
286 goto skip;
287 }
288 }
289
290 int canconsume;
291 while(c->mbulk > 0 && pos < len) {
292 if (c->readlen > 0) {
293 canconsume = c->readlen > (len-pos) ? (len-pos) : c->readlen;
294 c->readlen -= canconsume;
295 pos += canconsume;
296 if (c->readlen == 0)
297 c->mbulk--;
2fd30952 298 } else {
36babc1e
PN
299 advance = readLen(c->ibuf+pos,&c->readlen);
300 if (advance) {
301 pos += advance;
302 if (c->readlen == -1) {
303 c->mbulk--;
304 continue;
305 } else {
306 /* include the trailing \r\n */
307 c->readlen += 2;
308 }
309 } else {
310 goto skip;
311 }
2fd30952 312 }
313 }
36babc1e
PN
314
315 if (c->mbulk == 0)
316 goto done;
2fd30952 317 }
36babc1e
PN
318
319skip:
320 c->ibuf = sdsrange(c->ibuf,pos,-1);
321 return;
322done:
323 clientDone(c);
324 return;
ed9b544e 325}
326
327static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask)
328{
329 client c = privdata;
330 REDIS_NOTUSED(el);
331 REDIS_NOTUSED(fd);
332 REDIS_NOTUSED(mask);
333
334 if (c->state == CLIENT_CONNECTING) {
335 c->state = CLIENT_SENDQUERY;
336 c->start = mstime();
337 }
338 if (sdslen(c->obuf) > c->written) {
339 void *ptr = c->obuf+c->written;
340 int len = sdslen(c->obuf) - c->written;
341 int nwritten = write(c->fd, ptr, len);
342 if (nwritten == -1) {
61c47ecd 343 if (errno != EPIPE)
344 fprintf(stderr, "Writing to socket: %s\n", strerror(errno));
ed9b544e 345 freeClient(c);
346 return;
347 }
348 c->written += nwritten;
349 if (sdslen(c->obuf) == c->written) {
350 aeDeleteFileEvent(config.el,c->fd,AE_WRITABLE);
266373b2 351 aeCreateFileEvent(config.el,c->fd,AE_READABLE,readHandler,c);
ed9b544e 352 c->state = CLIENT_READREPLY;
353 }
354 }
355}
356
357static client createClient(void) {
358 client c = zmalloc(sizeof(struct _client));
359 char err[ANET_ERR_LEN];
360
361 c->fd = anetTcpNonBlockConnect(err,config.hostip,config.hostport);
362 if (c->fd == ANET_ERR) {
363 zfree(c);
364 fprintf(stderr,"Connect: %s\n",err);
365 return NULL;
366 }
367 anetTcpNoDelay(NULL,c->fd);
368 c->obuf = sdsempty();
369 c->ibuf = sdsempty();
2fd30952 370 c->mbulk = -1;
ed9b544e 371 c->readlen = 0;
372 c->written = 0;
58cd7103 373 c->totreceived = 0;
ed9b544e 374 c->state = CLIENT_CONNECTING;
266373b2 375 aeCreateFileEvent(config.el, c->fd, AE_WRITABLE, writeHandler, c);
ed9b544e 376 config.liveclients++;
377 listAddNodeTail(config.clients,c);
378 return c;
379}
380
381static void createMissingClients(client c) {
382 while(config.liveclients < config.numclients) {
383 client new = createClient();
384 if (!new) continue;
385 sdsfree(new->obuf);
386 new->obuf = sdsdup(c->obuf);
ecfaf6da 387 if (config.randomkeys) randomizeClientKey(c);
b892cabe 388 prepareClientForReply(new,c->replytype);
ed9b544e 389 }
390}
391
392static void showLatencyReport(char *title) {
393 int j, seen = 0;
394 float perc, reqpersec;
395
396 reqpersec = (float)config.donerequests/((float)config.totlatency/1000);
397 if (!config.quiet) {
398 printf("====== %s ======\n", title);
399 printf(" %d requests completed in %.2f seconds\n", config.donerequests,
400 (float)config.totlatency/1000);
401 printf(" %d parallel clients\n", config.numclients);
402 printf(" %d bytes payload\n", config.datasize);
403 printf(" keep alive: %d\n", config.keepalive);
404 printf("\n");
405 for (j = 0; j <= MAX_LATENCY; j++) {
406 if (config.latency[j]) {
407 seen += config.latency[j];
408 perc = ((float)seen*100)/config.donerequests;
409 printf("%.2f%% <= %d milliseconds\n", perc, j);
410 }
411 }
412 printf("%.2f requests per second\n\n", reqpersec);
413 } else {
414 printf("%s: %.2f requests per second\n", title, reqpersec);
415 }
416}
417
418static void prepareForBenchmark(void)
419{
420 memset(config.latency,0,sizeof(int)*(MAX_LATENCY+1));
421 config.start = mstime();
422 config.donerequests = 0;
423}
424
425static void endBenchmark(char *title) {
426 config.totlatency = mstime()-config.start;
427 showLatencyReport(title);
428 freeAllClients();
429}
430
431void parseOptions(int argc, char **argv) {
432 int i;
433
434 for (i = 1; i < argc; i++) {
435 int lastarg = i==argc-1;
436
437 if (!strcmp(argv[i],"-c") && !lastarg) {
438 config.numclients = atoi(argv[i+1]);
439 i++;
440 } else if (!strcmp(argv[i],"-n") && !lastarg) {
441 config.requests = atoi(argv[i+1]);
442 i++;
443 } else if (!strcmp(argv[i],"-k") && !lastarg) {
444 config.keepalive = atoi(argv[i+1]);
445 i++;
446 } else if (!strcmp(argv[i],"-h") && !lastarg) {
447 char *ip = zmalloc(32);
448 if (anetResolve(NULL,argv[i+1],ip) == ANET_ERR) {
449 printf("Can't resolve %s\n", argv[i]);
450 exit(1);
451 }
452 config.hostip = ip;
453 i++;
454 } else if (!strcmp(argv[i],"-p") && !lastarg) {
455 config.hostport = atoi(argv[i+1]);
456 i++;
457 } else if (!strcmp(argv[i],"-d") && !lastarg) {
458 config.datasize = atoi(argv[i+1]);
459 i++;
460 if (config.datasize < 1) config.datasize=1;
461 if (config.datasize > 1024*1024) config.datasize = 1024*1024;
ecfaf6da 462 } else if (!strcmp(argv[i],"-r") && !lastarg) {
57172ffb 463 config.randomkeys = 1;
ecfaf6da 464 config.randomkeys_keyspacelen = atoi(argv[i+1]);
465 if (config.randomkeys_keyspacelen < 0)
466 config.randomkeys_keyspacelen = 0;
467 i++;
ed9b544e 468 } else if (!strcmp(argv[i],"-q")) {
469 config.quiet = 1;
470 } else if (!strcmp(argv[i],"-l")) {
471 config.loop = 1;
58cd7103 472 } else if (!strcmp(argv[i],"-D")) {
473 config.debug = 1;
266373b2 474 } else if (!strcmp(argv[i],"-I")) {
475 config.idlemode = 1;
ed9b544e 476 } else {
477 printf("Wrong option '%s' or option argument missing\n\n",argv[i]);
478 printf("Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]\n\n");
479 printf(" -h <hostname> Server hostname (default 127.0.0.1)\n");
480 printf(" -p <hostname> Server port (default 6379)\n");
481 printf(" -c <clients> Number of parallel connections (default 50)\n");
482 printf(" -n <requests> Total number of requests (default 10000)\n");
483 printf(" -d <size> Data size of SET/GET value in bytes (default 2)\n");
484 printf(" -k <boolean> 1=keep alive 0=reconnect (default 1)\n");
b1ad58ed 485 printf(" -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD\n");
ecfaf6da 486 printf(" Using this option the benchmark will get/set keys\n");
487 printf(" in the form mykey_rand000000012456 instead of constant\n");
488 printf(" keys, the <keyspacelen> argument determines the max\n");
489 printf(" number of values for the random number. For instance\n");
490 printf(" if set to 10 only rand000000000000 - rand000000000009\n");
491 printf(" range will be allowed.\n");
ed9b544e 492 printf(" -q Quiet. Just show query/sec values\n");
493 printf(" -l Loop. Run the tests forever\n");
266373b2 494 printf(" -I Idle mode. Just open N idle connections and wait.\n");
58cd7103 495 printf(" -D Debug mode. more verbose.\n");
ed9b544e 496 exit(1);
497 }
498 }
499}
500
501int main(int argc, char **argv) {
502 client c;
503
504 signal(SIGHUP, SIG_IGN);
505 signal(SIGPIPE, SIG_IGN);
506
58cd7103 507 config.debug = 0;
ed9b544e 508 config.numclients = 50;
509 config.requests = 10000;
510 config.liveclients = 0;
511 config.el = aeCreateEventLoop();
512 config.keepalive = 1;
513 config.donerequests = 0;
514 config.datasize = 3;
57172ffb 515 config.randomkeys = 0;
ecfaf6da 516 config.randomkeys_keyspacelen = 0;
ed9b544e 517 config.quiet = 0;
518 config.loop = 0;
266373b2 519 config.idlemode = 0;
ed9b544e 520 config.latency = NULL;
521 config.clients = listCreate();
522 config.latency = zmalloc(sizeof(int)*(MAX_LATENCY+1));
523
524 config.hostip = "127.0.0.1";
525 config.hostport = 6379;
526
527 parseOptions(argc,argv);
528
529 if (config.keepalive == 0) {
c3251497 530 printf("WARNING: keepalive disabled, you probably need 'echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse' for Linux and 'sudo sysctl -w net.inet.tcp.msl=1000' for Mac OS X in order to use a lot of clients/requests\n");
ed9b544e 531 }
532
266373b2 533 if (config.idlemode) {
534 printf("Creating %d idle connections and waiting forever (Ctrl+C when done)\n", config.numclients);
535 prepareForBenchmark();
536 c = createClient();
537 if (!c) exit(1);
538 c->obuf = sdsempty();
539 prepareClientForReply(c,REPLY_RETCODE); /* will never receive it */
540 createMissingClients(c);
541 aeMain(config.el);
542 /* and will wait for every */
543 }
544
ed9b544e 545 do {
6766f45e 546 prepareForBenchmark();
547 c = createClient();
548 if (!c) exit(1);
549 c->obuf = sdscat(c->obuf,"PING\r\n");
550 prepareClientForReply(c,REPLY_RETCODE);
551 createMissingClients(c);
552 aeMain(config.el);
553 endBenchmark("PING");
554
555 prepareForBenchmark();
556 c = createClient();
557 if (!c) exit(1);
558 c->obuf = sdscat(c->obuf,"*1\r\n$4\r\nPING\r\n");
559 prepareClientForReply(c,REPLY_RETCODE);
560 createMissingClients(c);
561 aeMain(config.el);
562 endBenchmark("PING (multi bulk)");
563
ed9b544e 564 prepareForBenchmark();
565 c = createClient();
566 if (!c) exit(1);
57172ffb 567 c->obuf = sdscatprintf(c->obuf,"SET foo_rand000000000000 %d\r\n",config.datasize);
ed9b544e 568 {
569 char *data = zmalloc(config.datasize+2);
570 memset(data,'x',config.datasize);
571 data[config.datasize] = '\r';
572 data[config.datasize+1] = '\n';
573 c->obuf = sdscatlen(c->obuf,data,config.datasize+2);
574 }
2fd30952 575 prepareClientForReply(c,REPLY_RETCODE);
ed9b544e 576 createMissingClients(c);
577 aeMain(config.el);
578 endBenchmark("SET");
579
580 prepareForBenchmark();
581 c = createClient();
582 if (!c) exit(1);
57172ffb 583 c->obuf = sdscat(c->obuf,"GET foo_rand000000000000\r\n");
2fd30952 584 prepareClientForReply(c,REPLY_BULK);
ed9b544e 585 createMissingClients(c);
586 aeMain(config.el);
587 endBenchmark("GET");
588
589 prepareForBenchmark();
590 c = createClient();
591 if (!c) exit(1);
57172ffb 592 c->obuf = sdscat(c->obuf,"INCR counter_rand000000000000\r\n");
2fd30952 593 prepareClientForReply(c,REPLY_INT);
ed9b544e 594 createMissingClients(c);
595 aeMain(config.el);
596 endBenchmark("INCR");
597
598 prepareForBenchmark();
599 c = createClient();
600 if (!c) exit(1);
601 c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n");
2fd30952 602 prepareClientForReply(c,REPLY_INT);
ed9b544e 603 createMissingClients(c);
604 aeMain(config.el);
605 endBenchmark("LPUSH");
606
607 prepareForBenchmark();
608 c = createClient();
609 if (!c) exit(1);
610 c->obuf = sdscat(c->obuf,"LPOP mylist\r\n");
2fd30952 611 prepareClientForReply(c,REPLY_BULK);
ed9b544e 612 createMissingClients(c);
613 aeMain(config.el);
614 endBenchmark("LPOP");
615
b1ad58ed 616 prepareForBenchmark();
617 c = createClient();
618 if (!c) exit(1);
619 c->obuf = sdscat(c->obuf,"SADD myset 24\r\ncounter_rand000000000000\r\n");
620 prepareClientForReply(c,REPLY_RETCODE);
621 createMissingClients(c);
622 aeMain(config.el);
623 endBenchmark("SADD");
624
625 prepareForBenchmark();
626 c = createClient();
627 if (!c) exit(1);
628 c->obuf = sdscat(c->obuf,"SPOP myset\r\n");
629 prepareClientForReply(c,REPLY_BULK);
630 createMissingClients(c);
631 aeMain(config.el);
632 endBenchmark("SPOP");
633
2fd30952 634 prepareForBenchmark();
635 c = createClient();
636 if (!c) exit(1);
637 c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n");
638 prepareClientForReply(c,REPLY_RETCODE);
639 createMissingClients(c);
640 aeMain(config.el);
641 endBenchmark("LPUSH (again, in order to bench LRANGE)");
642
643 prepareForBenchmark();
644 c = createClient();
645 if (!c) exit(1);
646 c->obuf = sdscat(c->obuf,"LRANGE mylist 0 99\r\n");
647 prepareClientForReply(c,REPLY_MBULK);
648 createMissingClients(c);
649 aeMain(config.el);
650 endBenchmark("LRANGE (first 100 elements)");
651
ccb5332c 652 prepareForBenchmark();
653 c = createClient();
654 if (!c) exit(1);
655 c->obuf = sdscat(c->obuf,"LRANGE mylist 0 299\r\n");
656 prepareClientForReply(c,REPLY_MBULK);
657 createMissingClients(c);
658 aeMain(config.el);
659 endBenchmark("LRANGE (first 300 elements)");
660
cc30e368 661 prepareForBenchmark();
662 c = createClient();
663 if (!c) exit(1);
664 c->obuf = sdscat(c->obuf,"LRANGE mylist 0 449\r\n");
665 prepareClientForReply(c,REPLY_MBULK);
666 createMissingClients(c);
667 aeMain(config.el);
668 endBenchmark("LRANGE (first 450 elements)");
669
670 prepareForBenchmark();
671 c = createClient();
672 if (!c) exit(1);
673 c->obuf = sdscat(c->obuf,"LRANGE mylist 0 599\r\n");
674 prepareClientForReply(c,REPLY_MBULK);
675 createMissingClients(c);
676 aeMain(config.el);
677 endBenchmark("LRANGE (first 600 elements)");
678
ed9b544e 679 printf("\n");
680 } while(config.loop);
681
682 return 0;
683}