]>
Commit | Line | Data |
---|---|---|
ed9b544e | 1 | /* Redis benchmark utility. |
2 | * | |
3 | * Copyright (c) 2006-2009, Salvatore Sanfilippo <antirez at gmail dot com> | |
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 | ||
61 | static 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; | |
81 | } config; | |
82 | ||
83 | typedef struct _client { | |
84 | int state; | |
85 | int fd; | |
86 | sds obuf; | |
87 | sds ibuf; | |
2fd30952 | 88 | int mbulk; /* Number of elements in an mbulk reply */ |
ed9b544e | 89 | int readlen; /* readlen == -1 means read a single line */ |
58cd7103 | 90 | int totreceived; |
ed9b544e | 91 | unsigned int written; /* bytes of 'obuf' already written */ |
92 | int replytype; | |
93 | long long start; /* start time in milliseconds */ | |
94 | } *client; | |
95 | ||
96 | /* Prototypes */ | |
97 | static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask); | |
98 | static void createMissingClients(client c); | |
99 | ||
100 | /* Implementation */ | |
101 | static long long mstime(void) { | |
102 | struct timeval tv; | |
103 | long long mst; | |
104 | ||
105 | gettimeofday(&tv, NULL); | |
106 | mst = ((long)tv.tv_sec)*1000; | |
107 | mst += tv.tv_usec/1000; | |
108 | return mst; | |
109 | } | |
110 | ||
111 | static void freeClient(client c) { | |
112 | listNode *ln; | |
113 | ||
114 | aeDeleteFileEvent(config.el,c->fd,AE_WRITABLE); | |
115 | aeDeleteFileEvent(config.el,c->fd,AE_READABLE); | |
116 | sdsfree(c->ibuf); | |
117 | sdsfree(c->obuf); | |
118 | close(c->fd); | |
119 | zfree(c); | |
120 | config.liveclients--; | |
121 | ln = listSearchKey(config.clients,c); | |
122 | assert(ln != NULL); | |
123 | listDelNode(config.clients,ln); | |
124 | } | |
125 | ||
126 | static void freeAllClients(void) { | |
127 | listNode *ln = config.clients->head, *next; | |
128 | ||
129 | while(ln) { | |
130 | next = ln->next; | |
131 | freeClient(ln->value); | |
132 | ln = next; | |
133 | } | |
134 | } | |
135 | ||
136 | static void resetClient(client c) { | |
137 | aeDeleteFileEvent(config.el,c->fd,AE_WRITABLE); | |
138 | aeDeleteFileEvent(config.el,c->fd,AE_READABLE); | |
139 | aeCreateFileEvent(config.el,c->fd, AE_WRITABLE,writeHandler,c,NULL); | |
140 | sdsfree(c->ibuf); | |
141 | c->ibuf = sdsempty(); | |
89ee361e | 142 | c->readlen = (c->replytype == REPLY_BULK || |
143 | c->replytype == REPLY_MBULK) ? -1 : 0; | |
2fd30952 | 144 | c->mbulk = -1; |
ed9b544e | 145 | c->written = 0; |
58cd7103 | 146 | c->totreceived = 0; |
ed9b544e | 147 | c->state = CLIENT_SENDQUERY; |
148 | c->start = mstime(); | |
74077975 | 149 | createMissingClients(c); |
ed9b544e | 150 | } |
151 | ||
ecfaf6da | 152 | static void randomizeClientKey(client c) { |
153 | char *p; | |
154 | char buf[32]; | |
155 | long r; | |
156 | ||
157 | p = strstr(c->obuf, "_rand"); | |
158 | if (!p) return; | |
159 | p += 5; | |
160 | r = random() % config.randomkeys_keyspacelen; | |
161 | sprintf(buf,"%ld",r); | |
162 | memcpy(p,buf,strlen(buf)); | |
163 | } | |
164 | ||
2fd30952 | 165 | static void prepareClientForReply(client c, int type) { |
166 | if (type == REPLY_BULK) { | |
167 | c->replytype = REPLY_BULK; | |
168 | c->readlen = -1; | |
169 | } else if (type == REPLY_MBULK) { | |
170 | c->replytype = REPLY_MBULK; | |
171 | c->readlen = -1; | |
172 | c->mbulk = -1; | |
173 | } else { | |
174 | c->replytype = type; | |
175 | c->readlen = 0; | |
176 | } | |
177 | } | |
178 | ||
ed9b544e | 179 | static void clientDone(client c) { |
58cd7103 | 180 | static int last_tot_received = 1; |
181 | ||
ed9b544e | 182 | long long latency; |
183 | config.donerequests ++; | |
184 | latency = mstime() - c->start; | |
185 | if (latency > MAX_LATENCY) latency = MAX_LATENCY; | |
186 | config.latency[latency]++; | |
187 | ||
58cd7103 | 188 | if (config.debug && last_tot_received != c->totreceived) { |
189 | printf("Tot bytes received: %d\n", c->totreceived); | |
190 | last_tot_received = c->totreceived; | |
191 | } | |
ed9b544e | 192 | if (config.donerequests == config.requests) { |
193 | freeClient(c); | |
194 | aeStop(config.el); | |
195 | return; | |
196 | } | |
197 | if (config.keepalive) { | |
198 | resetClient(c); | |
ecfaf6da | 199 | if (config.randomkeys) randomizeClientKey(c); |
ed9b544e | 200 | } else { |
201 | config.liveclients--; | |
202 | createMissingClients(c); | |
203 | config.liveclients++; | |
204 | freeClient(c); | |
205 | } | |
206 | } | |
207 | ||
208 | static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) | |
209 | { | |
210 | char buf[1024]; | |
211 | int nread; | |
212 | client c = privdata; | |
213 | REDIS_NOTUSED(el); | |
214 | REDIS_NOTUSED(fd); | |
215 | REDIS_NOTUSED(mask); | |
216 | ||
217 | nread = read(c->fd, buf, 1024); | |
218 | if (nread == -1) { | |
219 | fprintf(stderr, "Reading from socket: %s\n", strerror(errno)); | |
220 | freeClient(c); | |
221 | return; | |
222 | } | |
223 | if (nread == 0) { | |
224 | fprintf(stderr, "EOF from client\n"); | |
225 | freeClient(c); | |
226 | return; | |
227 | } | |
58cd7103 | 228 | c->totreceived += nread; |
ed9b544e | 229 | c->ibuf = sdscatlen(c->ibuf,buf,nread); |
230 | ||
2fd30952 | 231 | processdata: |
6c4e61b3 | 232 | /* Are we waiting for the first line of the command of for sdf |
233 | * count in bulk or multi bulk operations? */ | |
ed9b544e | 234 | if (c->replytype == REPLY_INT || |
235 | c->replytype == REPLY_RETCODE || | |
2fd30952 | 236 | (c->replytype == REPLY_BULK && c->readlen == -1) || |
237 | (c->replytype == REPLY_MBULK && c->readlen == -1) || | |
238 | (c->replytype == REPLY_MBULK && c->mbulk == -1)) { | |
ed9b544e | 239 | char *p; |
240 | ||
6c4e61b3 | 241 | /* Check if the first line is complete. This is only true if |
242 | * there is a newline inside the buffer. */ | |
ed9b544e | 243 | if ((p = strchr(c->ibuf,'\n')) != NULL) { |
2fd30952 | 244 | if (c->replytype == REPLY_BULK || |
245 | (c->replytype == REPLY_MBULK && c->mbulk != -1)) | |
246 | { | |
6c4e61b3 | 247 | /* Read the count of a bulk reply (being it a single bulk or |
248 | * a multi bulk reply). "$<count>" for the protocol spec. */ | |
ed9b544e | 249 | *p = '\0'; |
250 | *(p-1) = '\0'; | |
4c26a79a | 251 | c->readlen = atoi(c->ibuf+1)+2; |
89ee361e | 252 | // printf("BULK ATOI: %s\n", c->ibuf+1); |
2fd30952 | 253 | /* Handle null bulk reply "$-1" */ |
ecfaf6da | 254 | if (c->readlen-2 == -1) { |
ed9b544e | 255 | clientDone(c); |
256 | return; | |
257 | } | |
2fd30952 | 258 | /* Leave all the rest in the input buffer */ |
259 | c->ibuf = sdsrange(c->ibuf,(p-c->ibuf)+1,-1); | |
6c4e61b3 | 260 | /* fall through to reach the point where the code will try |
261 | * to check if the bulk reply is complete. */ | |
2fd30952 | 262 | } else if (c->replytype == REPLY_MBULK && c->mbulk == -1) { |
6c4e61b3 | 263 | /* Read the count of a multi bulk reply. That is, how many |
264 | * bulk replies we have to read next. "*<count>" protocol. */ | |
2fd30952 | 265 | *p = '\0'; |
266 | *(p-1) = '\0'; | |
267 | c->mbulk = atoi(c->ibuf+1); | |
268 | /* Handle null bulk reply "*-1" */ | |
269 | if (c->mbulk == -1) { | |
270 | clientDone(c); | |
271 | return; | |
272 | } | |
89ee361e | 273 | // printf("%p) %d elements list\n", c, c->mbulk); |
2fd30952 | 274 | /* Leave all the rest in the input buffer */ |
ed9b544e | 275 | c->ibuf = sdsrange(c->ibuf,(p-c->ibuf)+1,-1); |
2fd30952 | 276 | goto processdata; |
ed9b544e | 277 | } else { |
278 | c->ibuf = sdstrim(c->ibuf,"\r\n"); | |
279 | clientDone(c); | |
280 | return; | |
281 | } | |
282 | } | |
283 | } | |
2fd30952 | 284 | /* bulk read, did we read everything? */ |
6c4e61b3 | 285 | if (((c->replytype == REPLY_MBULK && c->mbulk != -1) || |
286 | (c->replytype == REPLY_BULK)) && c->readlen != -1 && | |
287 | (unsigned)c->readlen <= sdslen(c->ibuf)) | |
2fd30952 | 288 | { |
89ee361e | 289 | // printf("BULKSTATUS mbulk:%d readlen:%d sdslen:%d\n", |
290 | // c->mbulk,c->readlen,sdslen(c->ibuf)); | |
2fd30952 | 291 | if (c->replytype == REPLY_BULK) { |
292 | clientDone(c); | |
293 | } else if (c->replytype == REPLY_MBULK) { | |
89ee361e | 294 | // printf("%p) %d (%d)) ",c, c->mbulk, c->readlen); |
295 | // fwrite(c->ibuf,c->readlen,1,stdout); | |
296 | // printf("\n"); | |
2fd30952 | 297 | if (--c->mbulk == 0) { |
298 | clientDone(c); | |
299 | } else { | |
300 | c->ibuf = sdsrange(c->ibuf,c->readlen,-1); | |
301 | c->readlen = -1; | |
302 | goto processdata; | |
303 | } | |
304 | } | |
305 | } | |
ed9b544e | 306 | } |
307 | ||
308 | static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) | |
309 | { | |
310 | client c = privdata; | |
311 | REDIS_NOTUSED(el); | |
312 | REDIS_NOTUSED(fd); | |
313 | REDIS_NOTUSED(mask); | |
314 | ||
315 | if (c->state == CLIENT_CONNECTING) { | |
316 | c->state = CLIENT_SENDQUERY; | |
317 | c->start = mstime(); | |
318 | } | |
319 | if (sdslen(c->obuf) > c->written) { | |
320 | void *ptr = c->obuf+c->written; | |
321 | int len = sdslen(c->obuf) - c->written; | |
322 | int nwritten = write(c->fd, ptr, len); | |
323 | if (nwritten == -1) { | |
324 | fprintf(stderr, "Writing to socket: %s\n", strerror(errno)); | |
325 | freeClient(c); | |
326 | return; | |
327 | } | |
328 | c->written += nwritten; | |
329 | if (sdslen(c->obuf) == c->written) { | |
330 | aeDeleteFileEvent(config.el,c->fd,AE_WRITABLE); | |
331 | aeCreateFileEvent(config.el,c->fd,AE_READABLE,readHandler,c,NULL); | |
332 | c->state = CLIENT_READREPLY; | |
333 | } | |
334 | } | |
335 | } | |
336 | ||
337 | static client createClient(void) { | |
338 | client c = zmalloc(sizeof(struct _client)); | |
339 | char err[ANET_ERR_LEN]; | |
340 | ||
341 | c->fd = anetTcpNonBlockConnect(err,config.hostip,config.hostport); | |
342 | if (c->fd == ANET_ERR) { | |
343 | zfree(c); | |
344 | fprintf(stderr,"Connect: %s\n",err); | |
345 | return NULL; | |
346 | } | |
347 | anetTcpNoDelay(NULL,c->fd); | |
348 | c->obuf = sdsempty(); | |
349 | c->ibuf = sdsempty(); | |
2fd30952 | 350 | c->mbulk = -1; |
ed9b544e | 351 | c->readlen = 0; |
352 | c->written = 0; | |
58cd7103 | 353 | c->totreceived = 0; |
ed9b544e | 354 | c->state = CLIENT_CONNECTING; |
355 | aeCreateFileEvent(config.el, c->fd, AE_WRITABLE, writeHandler, c, NULL); | |
356 | config.liveclients++; | |
357 | listAddNodeTail(config.clients,c); | |
358 | return c; | |
359 | } | |
360 | ||
361 | static void createMissingClients(client c) { | |
362 | while(config.liveclients < config.numclients) { | |
363 | client new = createClient(); | |
364 | if (!new) continue; | |
365 | sdsfree(new->obuf); | |
366 | new->obuf = sdsdup(c->obuf); | |
ecfaf6da | 367 | if (config.randomkeys) randomizeClientKey(c); |
b892cabe | 368 | prepareClientForReply(new,c->replytype); |
ed9b544e | 369 | } |
370 | } | |
371 | ||
372 | static void showLatencyReport(char *title) { | |
373 | int j, seen = 0; | |
374 | float perc, reqpersec; | |
375 | ||
376 | reqpersec = (float)config.donerequests/((float)config.totlatency/1000); | |
377 | if (!config.quiet) { | |
378 | printf("====== %s ======\n", title); | |
379 | printf(" %d requests completed in %.2f seconds\n", config.donerequests, | |
380 | (float)config.totlatency/1000); | |
381 | printf(" %d parallel clients\n", config.numclients); | |
382 | printf(" %d bytes payload\n", config.datasize); | |
383 | printf(" keep alive: %d\n", config.keepalive); | |
384 | printf("\n"); | |
385 | for (j = 0; j <= MAX_LATENCY; j++) { | |
386 | if (config.latency[j]) { | |
387 | seen += config.latency[j]; | |
388 | perc = ((float)seen*100)/config.donerequests; | |
389 | printf("%.2f%% <= %d milliseconds\n", perc, j); | |
390 | } | |
391 | } | |
392 | printf("%.2f requests per second\n\n", reqpersec); | |
393 | } else { | |
394 | printf("%s: %.2f requests per second\n", title, reqpersec); | |
395 | } | |
396 | } | |
397 | ||
398 | static void prepareForBenchmark(void) | |
399 | { | |
400 | memset(config.latency,0,sizeof(int)*(MAX_LATENCY+1)); | |
401 | config.start = mstime(); | |
402 | config.donerequests = 0; | |
403 | } | |
404 | ||
405 | static void endBenchmark(char *title) { | |
406 | config.totlatency = mstime()-config.start; | |
407 | showLatencyReport(title); | |
408 | freeAllClients(); | |
409 | } | |
410 | ||
411 | void parseOptions(int argc, char **argv) { | |
412 | int i; | |
413 | ||
414 | for (i = 1; i < argc; i++) { | |
415 | int lastarg = i==argc-1; | |
416 | ||
417 | if (!strcmp(argv[i],"-c") && !lastarg) { | |
418 | config.numclients = atoi(argv[i+1]); | |
419 | i++; | |
420 | } else if (!strcmp(argv[i],"-n") && !lastarg) { | |
421 | config.requests = atoi(argv[i+1]); | |
422 | i++; | |
423 | } else if (!strcmp(argv[i],"-k") && !lastarg) { | |
424 | config.keepalive = atoi(argv[i+1]); | |
425 | i++; | |
426 | } else if (!strcmp(argv[i],"-h") && !lastarg) { | |
427 | char *ip = zmalloc(32); | |
428 | if (anetResolve(NULL,argv[i+1],ip) == ANET_ERR) { | |
429 | printf("Can't resolve %s\n", argv[i]); | |
430 | exit(1); | |
431 | } | |
432 | config.hostip = ip; | |
433 | i++; | |
434 | } else if (!strcmp(argv[i],"-p") && !lastarg) { | |
435 | config.hostport = atoi(argv[i+1]); | |
436 | i++; | |
437 | } else if (!strcmp(argv[i],"-d") && !lastarg) { | |
438 | config.datasize = atoi(argv[i+1]); | |
439 | i++; | |
440 | if (config.datasize < 1) config.datasize=1; | |
441 | if (config.datasize > 1024*1024) config.datasize = 1024*1024; | |
ecfaf6da | 442 | } else if (!strcmp(argv[i],"-r") && !lastarg) { |
57172ffb | 443 | config.randomkeys = 1; |
ecfaf6da | 444 | config.randomkeys_keyspacelen = atoi(argv[i+1]); |
445 | if (config.randomkeys_keyspacelen < 0) | |
446 | config.randomkeys_keyspacelen = 0; | |
447 | i++; | |
ed9b544e | 448 | } else if (!strcmp(argv[i],"-q")) { |
449 | config.quiet = 1; | |
450 | } else if (!strcmp(argv[i],"-l")) { | |
451 | config.loop = 1; | |
58cd7103 | 452 | } else if (!strcmp(argv[i],"-D")) { |
453 | config.debug = 1; | |
ed9b544e | 454 | } else { |
455 | printf("Wrong option '%s' or option argument missing\n\n",argv[i]); | |
456 | printf("Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]\n\n"); | |
457 | printf(" -h <hostname> Server hostname (default 127.0.0.1)\n"); | |
458 | printf(" -p <hostname> Server port (default 6379)\n"); | |
459 | printf(" -c <clients> Number of parallel connections (default 50)\n"); | |
460 | printf(" -n <requests> Total number of requests (default 10000)\n"); | |
461 | printf(" -d <size> Data size of SET/GET value in bytes (default 2)\n"); | |
462 | printf(" -k <boolean> 1=keep alive 0=reconnect (default 1)\n"); | |
ecfaf6da | 463 | printf(" -r <keyspacelen> Use random keys for SET/GET/INCR\n"); |
464 | printf(" Using this option the benchmark will get/set keys\n"); | |
465 | printf(" in the form mykey_rand000000012456 instead of constant\n"); | |
466 | printf(" keys, the <keyspacelen> argument determines the max\n"); | |
467 | printf(" number of values for the random number. For instance\n"); | |
468 | printf(" if set to 10 only rand000000000000 - rand000000000009\n"); | |
469 | printf(" range will be allowed.\n"); | |
ed9b544e | 470 | printf(" -q Quiet. Just show query/sec values\n"); |
471 | printf(" -l Loop. Run the tests forever\n"); | |
58cd7103 | 472 | printf(" -D Debug mode. more verbose.\n"); |
ed9b544e | 473 | exit(1); |
474 | } | |
475 | } | |
476 | } | |
477 | ||
478 | int main(int argc, char **argv) { | |
479 | client c; | |
480 | ||
481 | signal(SIGHUP, SIG_IGN); | |
482 | signal(SIGPIPE, SIG_IGN); | |
483 | ||
58cd7103 | 484 | config.debug = 0; |
ed9b544e | 485 | config.numclients = 50; |
486 | config.requests = 10000; | |
487 | config.liveclients = 0; | |
488 | config.el = aeCreateEventLoop(); | |
489 | config.keepalive = 1; | |
490 | config.donerequests = 0; | |
491 | config.datasize = 3; | |
57172ffb | 492 | config.randomkeys = 0; |
ecfaf6da | 493 | config.randomkeys_keyspacelen = 0; |
ed9b544e | 494 | config.quiet = 0; |
495 | config.loop = 0; | |
496 | config.latency = NULL; | |
497 | config.clients = listCreate(); | |
498 | config.latency = zmalloc(sizeof(int)*(MAX_LATENCY+1)); | |
499 | ||
500 | config.hostip = "127.0.0.1"; | |
501 | config.hostport = 6379; | |
502 | ||
503 | parseOptions(argc,argv); | |
504 | ||
505 | if (config.keepalive == 0) { | |
c3251497 | 506 | 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 | 507 | } |
508 | ||
509 | do { | |
ed9b544e | 510 | prepareForBenchmark(); |
511 | c = createClient(); | |
512 | if (!c) exit(1); | |
57172ffb | 513 | c->obuf = sdscatprintf(c->obuf,"SET foo_rand000000000000 %d\r\n",config.datasize); |
ed9b544e | 514 | { |
515 | char *data = zmalloc(config.datasize+2); | |
516 | memset(data,'x',config.datasize); | |
517 | data[config.datasize] = '\r'; | |
518 | data[config.datasize+1] = '\n'; | |
519 | c->obuf = sdscatlen(c->obuf,data,config.datasize+2); | |
520 | } | |
2fd30952 | 521 | prepareClientForReply(c,REPLY_RETCODE); |
ed9b544e | 522 | createMissingClients(c); |
523 | aeMain(config.el); | |
524 | endBenchmark("SET"); | |
525 | ||
526 | prepareForBenchmark(); | |
527 | c = createClient(); | |
528 | if (!c) exit(1); | |
57172ffb | 529 | c->obuf = sdscat(c->obuf,"GET foo_rand000000000000\r\n"); |
2fd30952 | 530 | prepareClientForReply(c,REPLY_BULK); |
ed9b544e | 531 | createMissingClients(c); |
532 | aeMain(config.el); | |
533 | endBenchmark("GET"); | |
534 | ||
535 | prepareForBenchmark(); | |
536 | c = createClient(); | |
537 | if (!c) exit(1); | |
57172ffb | 538 | c->obuf = sdscat(c->obuf,"INCR counter_rand000000000000\r\n"); |
2fd30952 | 539 | prepareClientForReply(c,REPLY_INT); |
ed9b544e | 540 | createMissingClients(c); |
541 | aeMain(config.el); | |
542 | endBenchmark("INCR"); | |
543 | ||
544 | prepareForBenchmark(); | |
545 | c = createClient(); | |
546 | if (!c) exit(1); | |
547 | c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n"); | |
2fd30952 | 548 | prepareClientForReply(c,REPLY_INT); |
ed9b544e | 549 | createMissingClients(c); |
550 | aeMain(config.el); | |
551 | endBenchmark("LPUSH"); | |
552 | ||
553 | prepareForBenchmark(); | |
554 | c = createClient(); | |
555 | if (!c) exit(1); | |
556 | c->obuf = sdscat(c->obuf,"LPOP mylist\r\n"); | |
2fd30952 | 557 | prepareClientForReply(c,REPLY_BULK); |
ed9b544e | 558 | createMissingClients(c); |
559 | aeMain(config.el); | |
560 | endBenchmark("LPOP"); | |
561 | ||
9f3c422c | 562 | prepareForBenchmark(); |
563 | c = createClient(); | |
564 | if (!c) exit(1); | |
565 | c->obuf = sdscat(c->obuf,"PING\r\n"); | |
2fd30952 | 566 | prepareClientForReply(c,REPLY_RETCODE); |
9f3c422c | 567 | createMissingClients(c); |
568 | aeMain(config.el); | |
569 | endBenchmark("PING"); | |
570 | ||
2fd30952 | 571 | prepareForBenchmark(); |
572 | c = createClient(); | |
573 | if (!c) exit(1); | |
574 | c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n"); | |
575 | prepareClientForReply(c,REPLY_RETCODE); | |
576 | createMissingClients(c); | |
577 | aeMain(config.el); | |
578 | endBenchmark("LPUSH (again, in order to bench LRANGE)"); | |
579 | ||
580 | prepareForBenchmark(); | |
581 | c = createClient(); | |
582 | if (!c) exit(1); | |
583 | c->obuf = sdscat(c->obuf,"LRANGE mylist 0 99\r\n"); | |
584 | prepareClientForReply(c,REPLY_MBULK); | |
585 | createMissingClients(c); | |
586 | aeMain(config.el); | |
587 | endBenchmark("LRANGE (first 100 elements)"); | |
588 | ||
ccb5332c | 589 | prepareForBenchmark(); |
590 | c = createClient(); | |
591 | if (!c) exit(1); | |
592 | c->obuf = sdscat(c->obuf,"LRANGE mylist 0 299\r\n"); | |
593 | prepareClientForReply(c,REPLY_MBULK); | |
594 | createMissingClients(c); | |
595 | aeMain(config.el); | |
596 | endBenchmark("LRANGE (first 300 elements)"); | |
597 | ||
cc30e368 | 598 | prepareForBenchmark(); |
599 | c = createClient(); | |
600 | if (!c) exit(1); | |
601 | c->obuf = sdscat(c->obuf,"LRANGE mylist 0 449\r\n"); | |
602 | prepareClientForReply(c,REPLY_MBULK); | |
603 | createMissingClients(c); | |
604 | aeMain(config.el); | |
605 | endBenchmark("LRANGE (first 450 elements)"); | |
606 | ||
607 | prepareForBenchmark(); | |
608 | c = createClient(); | |
609 | if (!c) exit(1); | |
610 | c->obuf = sdscat(c->obuf,"LRANGE mylist 0 599\r\n"); | |
611 | prepareClientForReply(c,REPLY_MBULK); | |
612 | createMissingClients(c); | |
613 | aeMain(config.el); | |
614 | endBenchmark("LRANGE (first 600 elements)"); | |
615 | ||
ed9b544e | 616 | printf("\n"); |
617 | } while(config.loop); | |
618 | ||
619 | return 0; | |
620 | } |