]>
Commit | Line | Data |
---|---|---|
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" | |
ec8f0667 | 43 | #include "hiredis.h" |
ed9b544e | 44 | #include "sds.h" |
45 | #include "adlist.h" | |
46 | #include "zmalloc.h" | |
47 | ||
ed9b544e | 48 | #define CLIENT_CONNECTING 0 |
49 | #define CLIENT_SENDQUERY 1 | |
50 | #define CLIENT_READREPLY 2 | |
51 | ||
ed9b544e | 52 | #define REDIS_NOTUSED(V) ((void) V) |
53 | ||
54 | static struct config { | |
58cd7103 | 55 | int debug; |
ed9b544e | 56 | int numclients; |
57 | int requests; | |
58 | int liveclients; | |
59 | int donerequests; | |
60 | int keysize; | |
61 | int datasize; | |
57172ffb | 62 | int randomkeys; |
ecfaf6da | 63 | int randomkeys_keyspacelen; |
ed9b544e | 64 | aeEventLoop *el; |
65 | char *hostip; | |
66 | int hostport; | |
c61e6925 | 67 | char *hostsocket; |
ed9b544e | 68 | int keepalive; |
69 | long long start; | |
70 | long long totlatency; | |
8146e316 | 71 | long long *latency; |
ed0dd554 | 72 | char *title; |
ed9b544e | 73 | list *clients; |
74 | int quiet; | |
75 | int loop; | |
266373b2 | 76 | int idlemode; |
ed9b544e | 77 | } config; |
78 | ||
79 | typedef struct _client { | |
ec8f0667 | 80 | redisContext *context; |
ed9b544e | 81 | int state; |
ed9b544e | 82 | sds obuf; |
1cd3c1e0 | 83 | char *randptr; |
8146e316 | 84 | unsigned int written; /* bytes of 'obuf' already written */ |
ed9b544e | 85 | int replytype; |
8146e316 PN |
86 | long long start; /* start time of a request */ |
87 | long long latency; /* request latency */ | |
ed9b544e | 88 | } *client; |
89 | ||
90 | /* Prototypes */ | |
91 | static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask); | |
92 | static void createMissingClients(client c); | |
93 | ||
94 | /* Implementation */ | |
8146e316 PN |
95 | static long long ustime(void) { |
96 | struct timeval tv; | |
97 | long long ust; | |
98 | ||
99 | gettimeofday(&tv, NULL); | |
100 | ust = ((long)tv.tv_sec)*1000000; | |
101 | ust += tv.tv_usec; | |
102 | return ust; | |
103 | } | |
104 | ||
ed9b544e | 105 | static long long mstime(void) { |
106 | struct timeval tv; | |
107 | long long mst; | |
108 | ||
109 | gettimeofday(&tv, NULL); | |
110 | mst = ((long)tv.tv_sec)*1000; | |
111 | mst += tv.tv_usec/1000; | |
112 | return mst; | |
113 | } | |
114 | ||
115 | static void freeClient(client c) { | |
116 | listNode *ln; | |
ec8f0667 PN |
117 | aeDeleteFileEvent(config.el,c->context->fd,AE_WRITABLE); |
118 | aeDeleteFileEvent(config.el,c->context->fd,AE_READABLE); | |
119 | redisFree(c->context); | |
ed9b544e | 120 | sdsfree(c->obuf); |
ed9b544e | 121 | zfree(c); |
122 | config.liveclients--; | |
123 | ln = listSearchKey(config.clients,c); | |
124 | assert(ln != NULL); | |
125 | listDelNode(config.clients,ln); | |
126 | } | |
127 | ||
128 | static void freeAllClients(void) { | |
129 | listNode *ln = config.clients->head, *next; | |
130 | ||
131 | while(ln) { | |
132 | next = ln->next; | |
133 | freeClient(ln->value); | |
134 | ln = next; | |
135 | } | |
136 | } | |
137 | ||
138 | static void resetClient(client c) { | |
ec8f0667 PN |
139 | aeDeleteFileEvent(config.el,c->context->fd,AE_WRITABLE); |
140 | aeDeleteFileEvent(config.el,c->context->fd,AE_READABLE); | |
141 | aeCreateFileEvent(config.el,c->context->fd,AE_WRITABLE,writeHandler,c); | |
ed9b544e | 142 | c->written = 0; |
143 | c->state = CLIENT_SENDQUERY; | |
8146e316 PN |
144 | c->start = ustime(); |
145 | c->latency = -1; | |
ed9b544e | 146 | } |
147 | ||
ecfaf6da | 148 | static void randomizeClientKey(client c) { |
1cd3c1e0 | 149 | char *p, *newline; |
ecfaf6da | 150 | char buf[32]; |
151 | long r; | |
152 | ||
1cd3c1e0 PN |
153 | if (c->randptr == NULL) return; |
154 | ||
155 | /* Check if we have to randomize (only once per connection) */ | |
156 | if (c->randptr == (void*)-1) { | |
157 | p = strstr(c->obuf,":rand:"); | |
158 | if (!p) { | |
159 | c->randptr = NULL; | |
160 | return; | |
161 | } else { | |
162 | newline = strstr(p,"\r\n"); | |
163 | assert(newline-(p+6) == 12); /* 12 chars for randomness */ | |
164 | c->randptr = p+6; | |
165 | } | |
166 | } | |
167 | ||
168 | /* Set random number in output buffer */ | |
ecfaf6da | 169 | r = random() % config.randomkeys_keyspacelen; |
1cd3c1e0 PN |
170 | snprintf(buf,sizeof(buf),"%012ld",r); |
171 | memcpy(c->randptr,buf,12); | |
ecfaf6da | 172 | } |
173 | ||
ed9b544e | 174 | static void clientDone(client c) { |
ed9b544e | 175 | if (config.donerequests == config.requests) { |
176 | freeClient(c); | |
177 | aeStop(config.el); | |
178 | return; | |
179 | } | |
180 | if (config.keepalive) { | |
181 | resetClient(c); | |
ecfaf6da | 182 | if (config.randomkeys) randomizeClientKey(c); |
ed9b544e | 183 | } else { |
184 | config.liveclients--; | |
185 | createMissingClients(c); | |
186 | config.liveclients++; | |
187 | freeClient(c); | |
188 | } | |
189 | } | |
190 | ||
ec8f0667 | 191 | static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) { |
ed9b544e | 192 | client c = privdata; |
ec8f0667 | 193 | void *reply = NULL; |
ed9b544e | 194 | REDIS_NOTUSED(el); |
195 | REDIS_NOTUSED(fd); | |
196 | REDIS_NOTUSED(mask); | |
197 | ||
8146e316 PN |
198 | /* Calculate latency only for the first read event. This means that the |
199 | * server already sent the reply and we need to parse it. Parsing overhead | |
200 | * is not part of the latency, so calculate it only once, here. */ | |
201 | if (c->latency < 0) c->latency = ustime()-(c->start); | |
202 | ||
ec8f0667 PN |
203 | if (redisBufferRead(c->context) != REDIS_OK) { |
204 | fprintf(stderr,"Error: %s\n",c->context->errstr); | |
205 | exit(1); | |
206 | } else { | |
207 | if (redisGetReply(c->context,&reply) != REDIS_OK) { | |
208 | fprintf(stderr,"Error: %s\n",c->context->errstr); | |
209 | exit(1); | |
2fd30952 | 210 | } |
8146e316 | 211 | if (reply != NULL) { |
53f1d817 PN |
212 | if (reply == (void*)REDIS_REPLY_ERROR) { |
213 | fprintf(stderr,"Unexpected error reply, exiting...\n"); | |
214 | exit(1); | |
215 | } | |
216 | ||
8146e316 PN |
217 | if (config.donerequests < config.requests) |
218 | config.latency[config.donerequests++] = c->latency; | |
ec8f0667 | 219 | clientDone(c); |
8146e316 | 220 | } |
2fd30952 | 221 | } |
ed9b544e | 222 | } |
223 | ||
ec8f0667 | 224 | static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) { |
ed9b544e | 225 | client c = privdata; |
226 | REDIS_NOTUSED(el); | |
227 | REDIS_NOTUSED(fd); | |
228 | REDIS_NOTUSED(mask); | |
229 | ||
230 | if (c->state == CLIENT_CONNECTING) { | |
231 | c->state = CLIENT_SENDQUERY; | |
8146e316 PN |
232 | c->start = ustime(); |
233 | c->latency = -1; | |
ed9b544e | 234 | } |
235 | if (sdslen(c->obuf) > c->written) { | |
236 | void *ptr = c->obuf+c->written; | |
ec8f0667 | 237 | int nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written); |
ed9b544e | 238 | if (nwritten == -1) { |
61c47ecd | 239 | if (errno != EPIPE) |
240 | fprintf(stderr, "Writing to socket: %s\n", strerror(errno)); | |
ed9b544e | 241 | freeClient(c); |
242 | return; | |
243 | } | |
244 | c->written += nwritten; | |
245 | if (sdslen(c->obuf) == c->written) { | |
ec8f0667 PN |
246 | aeDeleteFileEvent(config.el,c->context->fd,AE_WRITABLE); |
247 | aeCreateFileEvent(config.el,c->context->fd,AE_READABLE,readHandler,c); | |
ed9b544e | 248 | c->state = CLIENT_READREPLY; |
249 | } | |
250 | } | |
251 | } | |
252 | ||
ec8f0667 | 253 | static client createClient(int replytype) { |
ed9b544e | 254 | client c = zmalloc(sizeof(struct _client)); |
ec8f0667 PN |
255 | if (config.hostsocket == NULL) { |
256 | c->context = redisConnectNonBlock(config.hostip,config.hostport); | |
257 | } else { | |
258 | c->context = redisConnectUnixNonBlock(config.hostsocket); | |
ed9b544e | 259 | } |
ec8f0667 PN |
260 | if (c->context->err) { |
261 | fprintf(stderr,"Could not connect to Redis at "); | |
262 | if (config.hostsocket == NULL) | |
263 | fprintf(stderr,"%s:%d: %s\n",config.hostip,config.hostport,c->context->errstr); | |
264 | else | |
265 | fprintf(stderr,"%s: %s\n",config.hostsocket,c->context->errstr); | |
266 | exit(1); | |
267 | } | |
268 | c->replytype = replytype; | |
269 | c->state = CLIENT_CONNECTING; | |
1cd3c1e0 PN |
270 | c->obuf = NULL; |
271 | c->randptr = (void*)-1; | |
ed9b544e | 272 | c->written = 0; |
ec8f0667 PN |
273 | redisSetReplyObjectFunctions(c->context,NULL); |
274 | aeCreateFileEvent(config.el,c->context->fd,AE_WRITABLE,writeHandler,c); | |
ed9b544e | 275 | listAddNodeTail(config.clients,c); |
ec8f0667 | 276 | config.liveclients++; |
ed9b544e | 277 | return c; |
278 | } | |
279 | ||
280 | static void createMissingClients(client c) { | |
f474a5bd DS |
281 | int n = 0; |
282 | ||
ed9b544e | 283 | while(config.liveclients < config.numclients) { |
ec8f0667 | 284 | client new = createClient(c->replytype); |
ed9b544e | 285 | new->obuf = sdsdup(c->obuf); |
ecfaf6da | 286 | if (config.randomkeys) randomizeClientKey(c); |
f474a5bd DS |
287 | |
288 | /* Listen backlog is quite limited on most systems */ | |
289 | if (++n > 64) { | |
290 | usleep(50000); | |
291 | n = 0; | |
292 | } | |
ed9b544e | 293 | } |
f474a5bd DS |
294 | |
295 | /* Start the timer once the connection are established */ | |
296 | config.start = mstime(); | |
ed9b544e | 297 | } |
298 | ||
8146e316 PN |
299 | static int compareLatency(const void *a, const void *b) { |
300 | return (*(long long*)a)-(*(long long*)b); | |
301 | } | |
302 | ||
ed0dd554 | 303 | static void showLatencyReport(void) { |
8146e316 | 304 | int i, curlat = 0; |
ed9b544e | 305 | float perc, reqpersec; |
306 | ||
307 | reqpersec = (float)config.donerequests/((float)config.totlatency/1000); | |
308 | if (!config.quiet) { | |
ed0dd554 | 309 | printf("====== %s ======\n", config.title); |
ed9b544e | 310 | printf(" %d requests completed in %.2f seconds\n", config.donerequests, |
311 | (float)config.totlatency/1000); | |
312 | printf(" %d parallel clients\n", config.numclients); | |
313 | printf(" %d bytes payload\n", config.datasize); | |
314 | printf(" keep alive: %d\n", config.keepalive); | |
315 | printf("\n"); | |
8146e316 PN |
316 | |
317 | qsort(config.latency,config.requests,sizeof(long long),compareLatency); | |
318 | for (i = 0; i < config.requests; i++) { | |
319 | if (config.latency[i]/1000 != curlat || i == (config.requests-1)) { | |
320 | curlat = config.latency[i]/1000; | |
321 | perc = ((float)(i+1)*100)/config.requests; | |
322 | printf("%.2f%% <= %d milliseconds\n", perc, curlat); | |
ed9b544e | 323 | } |
324 | } | |
325 | printf("%.2f requests per second\n\n", reqpersec); | |
326 | } else { | |
ed0dd554 | 327 | printf("%s: %.2f requests per second\n", config.title, reqpersec); |
ed9b544e | 328 | } |
329 | } | |
330 | ||
ed0dd554 | 331 | static void prepareForBenchmark(char *title) { |
ed0dd554 | 332 | config.title = title; |
ed9b544e | 333 | config.start = mstime(); |
334 | config.donerequests = 0; | |
335 | } | |
336 | ||
ed0dd554 | 337 | static void endBenchmark(void) { |
ed9b544e | 338 | config.totlatency = mstime()-config.start; |
ed0dd554 | 339 | showLatencyReport(); |
ed9b544e | 340 | freeAllClients(); |
341 | } | |
342 | ||
343 | void parseOptions(int argc, char **argv) { | |
344 | int i; | |
345 | ||
346 | for (i = 1; i < argc; i++) { | |
347 | int lastarg = i==argc-1; | |
348 | ||
349 | if (!strcmp(argv[i],"-c") && !lastarg) { | |
350 | config.numclients = atoi(argv[i+1]); | |
351 | i++; | |
352 | } else if (!strcmp(argv[i],"-n") && !lastarg) { | |
353 | config.requests = atoi(argv[i+1]); | |
354 | i++; | |
355 | } else if (!strcmp(argv[i],"-k") && !lastarg) { | |
356 | config.keepalive = atoi(argv[i+1]); | |
357 | i++; | |
358 | } else if (!strcmp(argv[i],"-h") && !lastarg) { | |
ec8f0667 | 359 | config.hostip = argv[i+1]; |
ed9b544e | 360 | i++; |
361 | } else if (!strcmp(argv[i],"-p") && !lastarg) { | |
362 | config.hostport = atoi(argv[i+1]); | |
363 | i++; | |
c61e6925 PN |
364 | } else if (!strcmp(argv[i],"-s") && !lastarg) { |
365 | config.hostsocket = argv[i+1]; | |
366 | i++; | |
ed9b544e | 367 | } else if (!strcmp(argv[i],"-d") && !lastarg) { |
368 | config.datasize = atoi(argv[i+1]); | |
369 | i++; | |
370 | if (config.datasize < 1) config.datasize=1; | |
371 | if (config.datasize > 1024*1024) config.datasize = 1024*1024; | |
ecfaf6da | 372 | } else if (!strcmp(argv[i],"-r") && !lastarg) { |
57172ffb | 373 | config.randomkeys = 1; |
ecfaf6da | 374 | config.randomkeys_keyspacelen = atoi(argv[i+1]); |
375 | if (config.randomkeys_keyspacelen < 0) | |
376 | config.randomkeys_keyspacelen = 0; | |
377 | i++; | |
ed9b544e | 378 | } else if (!strcmp(argv[i],"-q")) { |
379 | config.quiet = 1; | |
380 | } else if (!strcmp(argv[i],"-l")) { | |
381 | config.loop = 1; | |
58cd7103 | 382 | } else if (!strcmp(argv[i],"-D")) { |
383 | config.debug = 1; | |
266373b2 | 384 | } else if (!strcmp(argv[i],"-I")) { |
385 | config.idlemode = 1; | |
ed9b544e | 386 | } else { |
387 | printf("Wrong option '%s' or option argument missing\n\n",argv[i]); | |
388 | printf("Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]\n\n"); | |
389 | printf(" -h <hostname> Server hostname (default 127.0.0.1)\n"); | |
c61e6925 PN |
390 | printf(" -p <port> Server port (default 6379)\n"); |
391 | printf(" -s <socket> Server socket (overrides host and port)\n"); | |
ed9b544e | 392 | printf(" -c <clients> Number of parallel connections (default 50)\n"); |
393 | printf(" -n <requests> Total number of requests (default 10000)\n"); | |
394 | printf(" -d <size> Data size of SET/GET value in bytes (default 2)\n"); | |
395 | printf(" -k <boolean> 1=keep alive 0=reconnect (default 1)\n"); | |
b1ad58ed | 396 | printf(" -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD\n"); |
ecfaf6da | 397 | printf(" Using this option the benchmark will get/set keys\n"); |
398 | printf(" in the form mykey_rand000000012456 instead of constant\n"); | |
399 | printf(" keys, the <keyspacelen> argument determines the max\n"); | |
400 | printf(" number of values for the random number. For instance\n"); | |
401 | printf(" if set to 10 only rand000000000000 - rand000000000009\n"); | |
402 | printf(" range will be allowed.\n"); | |
ed9b544e | 403 | printf(" -q Quiet. Just show query/sec values\n"); |
404 | printf(" -l Loop. Run the tests forever\n"); | |
266373b2 | 405 | printf(" -I Idle mode. Just open N idle connections and wait.\n"); |
58cd7103 | 406 | printf(" -D Debug mode. more verbose.\n"); |
ed9b544e | 407 | exit(1); |
408 | } | |
409 | } | |
410 | } | |
411 | ||
ed0dd554 PN |
412 | int showThroughput(struct aeEventLoop *eventLoop, long long id, void *clientData) { |
413 | REDIS_NOTUSED(eventLoop); | |
414 | REDIS_NOTUSED(id); | |
415 | REDIS_NOTUSED(clientData); | |
416 | ||
417 | float dt = (float)(mstime()-config.start)/1000.0; | |
418 | float rps = (float)config.donerequests/dt; | |
419 | printf("%s: %.2f\r", config.title, rps); | |
420 | fflush(stdout); | |
421 | return 250; /* every 250ms */ | |
422 | } | |
423 | ||
ed9b544e | 424 | int main(int argc, char **argv) { |
174df6fe | 425 | int i; |
ed9b544e | 426 | client c; |
427 | ||
428 | signal(SIGHUP, SIG_IGN); | |
429 | signal(SIGPIPE, SIG_IGN); | |
430 | ||
58cd7103 | 431 | config.debug = 0; |
ed9b544e | 432 | config.numclients = 50; |
433 | config.requests = 10000; | |
434 | config.liveclients = 0; | |
435 | config.el = aeCreateEventLoop(); | |
ed0dd554 | 436 | aeCreateTimeEvent(config.el,1,showThroughput,NULL,NULL); |
ed9b544e | 437 | config.keepalive = 1; |
438 | config.donerequests = 0; | |
439 | config.datasize = 3; | |
57172ffb | 440 | config.randomkeys = 0; |
ecfaf6da | 441 | config.randomkeys_keyspacelen = 0; |
ed9b544e | 442 | config.quiet = 0; |
443 | config.loop = 0; | |
266373b2 | 444 | config.idlemode = 0; |
ed9b544e | 445 | config.latency = NULL; |
446 | config.clients = listCreate(); | |
ed9b544e | 447 | config.hostip = "127.0.0.1"; |
448 | config.hostport = 6379; | |
c61e6925 | 449 | config.hostsocket = NULL; |
ed9b544e | 450 | |
451 | parseOptions(argc,argv); | |
8146e316 | 452 | config.latency = zmalloc(sizeof(long long)*config.requests); |
ed9b544e | 453 | |
454 | if (config.keepalive == 0) { | |
c3251497 | 455 | 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 | 456 | } |
457 | ||
266373b2 | 458 | if (config.idlemode) { |
459 | printf("Creating %d idle connections and waiting forever (Ctrl+C when done)\n", config.numclients); | |
ed0dd554 | 460 | prepareForBenchmark("IDLE"); |
ec8f0667 | 461 | c = createClient(0); /* will never receive a reply */ |
266373b2 | 462 | c->obuf = sdsempty(); |
266373b2 | 463 | createMissingClients(c); |
464 | aeMain(config.el); | |
465 | /* and will wait for every */ | |
466 | } | |
467 | ||
ed9b544e | 468 | do { |
1cd3c1e0 PN |
469 | char *data, *cmd; |
470 | int len; | |
471 | ||
472 | data = zmalloc(config.datasize+1); | |
174df6fe PN |
473 | memset(data,'x',config.datasize); |
474 | data[config.datasize] = '\0'; | |
475 | ||
1cd3c1e0 | 476 | prepareForBenchmark("PING (inline)"); |
ec8f0667 | 477 | c = createClient(REDIS_REPLY_STATUS); |
1cd3c1e0 | 478 | c->obuf = sdscat(sdsempty(),"PING\r\n"); |
6766f45e | 479 | createMissingClients(c); |
480 | aeMain(config.el); | |
ed0dd554 | 481 | endBenchmark(); |
6766f45e | 482 | |
1cd3c1e0 | 483 | prepareForBenchmark("PING"); |
ec8f0667 | 484 | c = createClient(REDIS_REPLY_STATUS); |
1cd3c1e0 PN |
485 | len = redisFormatCommand(&cmd,"PING"); |
486 | c->obuf = sdsnewlen(cmd,len); | |
487 | free(cmd); | |
6766f45e | 488 | createMissingClients(c); |
489 | aeMain(config.el); | |
ed0dd554 | 490 | endBenchmark(); |
6766f45e | 491 | |
1cd3c1e0 | 492 | prepareForBenchmark("MSET (10 keys)"); |
ec8f0667 | 493 | c = createClient(REDIS_REPLY_ARRAY); |
1cd3c1e0 PN |
494 | { |
495 | const char *argv[11]; | |
496 | argv[0] = "MSET"; | |
497 | for (i = 1; i < 11; i++) | |
498 | argv[i] = data; | |
499 | len = redisFormatCommandArgv(&cmd,11,argv,NULL); | |
500 | c->obuf = sdsnewlen(cmd,len); | |
501 | free(cmd); | |
502 | } | |
ea5b7092 PN |
503 | createMissingClients(c); |
504 | aeMain(config.el); | |
505 | endBenchmark(); | |
506 | ||
ed0dd554 | 507 | prepareForBenchmark("SET"); |
ec8f0667 | 508 | c = createClient(REDIS_REPLY_STATUS); |
1cd3c1e0 PN |
509 | len = redisFormatCommand(&cmd,"SET foo:rand:000000000000 %s",data); |
510 | c->obuf = sdsnewlen(cmd,len); | |
511 | free(cmd); | |
ed9b544e | 512 | createMissingClients(c); |
513 | aeMain(config.el); | |
ed0dd554 | 514 | endBenchmark(); |
ed9b544e | 515 | |
ed0dd554 | 516 | prepareForBenchmark("GET"); |
ec8f0667 | 517 | c = createClient(REDIS_REPLY_STRING); |
1cd3c1e0 PN |
518 | len = redisFormatCommand(&cmd,"GET foo:rand:000000000000"); |
519 | c->obuf = sdsnewlen(cmd,len); | |
520 | free(cmd); | |
ed9b544e | 521 | createMissingClients(c); |
522 | aeMain(config.el); | |
ed0dd554 | 523 | endBenchmark(); |
ed9b544e | 524 | |
ed0dd554 | 525 | prepareForBenchmark("INCR"); |
ec8f0667 | 526 | c = createClient(REDIS_REPLY_INTEGER); |
1cd3c1e0 PN |
527 | len = redisFormatCommand(&cmd,"INCR counter:rand:000000000000"); |
528 | c->obuf = sdsnewlen(cmd,len); | |
529 | free(cmd); | |
ed9b544e | 530 | createMissingClients(c); |
531 | aeMain(config.el); | |
ed0dd554 | 532 | endBenchmark(); |
ed9b544e | 533 | |
ed0dd554 | 534 | prepareForBenchmark("LPUSH"); |
ec8f0667 | 535 | c = createClient(REDIS_REPLY_INTEGER); |
1cd3c1e0 PN |
536 | len = redisFormatCommand(&cmd,"LPUSH mylist %s",data); |
537 | c->obuf = sdsnewlen(cmd,len); | |
538 | free(cmd); | |
ed9b544e | 539 | createMissingClients(c); |
540 | aeMain(config.el); | |
ed0dd554 | 541 | endBenchmark(); |
ed9b544e | 542 | |
ed0dd554 | 543 | prepareForBenchmark("LPOP"); |
ec8f0667 | 544 | c = createClient(REDIS_REPLY_STRING); |
1cd3c1e0 PN |
545 | len = redisFormatCommand(&cmd,"LPOP mylist"); |
546 | c->obuf = sdsnewlen(cmd,len); | |
547 | free(cmd); | |
ed9b544e | 548 | createMissingClients(c); |
549 | aeMain(config.el); | |
ed0dd554 | 550 | endBenchmark(); |
ed9b544e | 551 | |
ed0dd554 | 552 | prepareForBenchmark("SADD"); |
ec8f0667 | 553 | c = createClient(REDIS_REPLY_STATUS); |
1cd3c1e0 PN |
554 | len = redisFormatCommand(&cmd,"SADD myset counter:rand:000000000000"); |
555 | c->obuf = sdsnewlen(cmd,len); | |
556 | free(cmd); | |
b1ad58ed | 557 | createMissingClients(c); |
558 | aeMain(config.el); | |
ed0dd554 | 559 | endBenchmark(); |
b1ad58ed | 560 | |
ed0dd554 | 561 | prepareForBenchmark("SPOP"); |
ec8f0667 | 562 | c = createClient(REDIS_REPLY_STRING); |
1cd3c1e0 PN |
563 | len = redisFormatCommand(&cmd,"SPOP myset"); |
564 | c->obuf = sdsnewlen(cmd,len); | |
565 | free(cmd); | |
b1ad58ed | 566 | createMissingClients(c); |
567 | aeMain(config.el); | |
ed0dd554 | 568 | endBenchmark(); |
b1ad58ed | 569 | |
ed0dd554 | 570 | prepareForBenchmark("LPUSH (again, in order to bench LRANGE)"); |
ec8f0667 | 571 | c = createClient(REDIS_REPLY_STATUS); |
1cd3c1e0 PN |
572 | len = redisFormatCommand(&cmd,"LPUSH mylist %s",data); |
573 | c->obuf = sdsnewlen(cmd,len); | |
574 | free(cmd); | |
2fd30952 | 575 | createMissingClients(c); |
576 | aeMain(config.el); | |
ed0dd554 | 577 | endBenchmark(); |
2fd30952 | 578 | |
ed0dd554 | 579 | prepareForBenchmark("LRANGE (first 100 elements)"); |
ec8f0667 | 580 | c = createClient(REDIS_REPLY_ARRAY); |
1cd3c1e0 PN |
581 | len = redisFormatCommand(&cmd,"LRANGE mylist 0 99"); |
582 | c->obuf = sdsnewlen(cmd,len); | |
583 | free(cmd); | |
2fd30952 | 584 | createMissingClients(c); |
585 | aeMain(config.el); | |
ed0dd554 | 586 | endBenchmark(); |
2fd30952 | 587 | |
ed0dd554 | 588 | prepareForBenchmark("LRANGE (first 300 elements)"); |
ec8f0667 | 589 | c = createClient(REDIS_REPLY_ARRAY); |
1cd3c1e0 PN |
590 | len = redisFormatCommand(&cmd,"LRANGE mylist 0 299"); |
591 | c->obuf = sdsnewlen(cmd,len); | |
592 | free(cmd); | |
ccb5332c | 593 | createMissingClients(c); |
594 | aeMain(config.el); | |
ed0dd554 | 595 | endBenchmark(); |
ccb5332c | 596 | |
ed0dd554 | 597 | prepareForBenchmark("LRANGE (first 450 elements)"); |
ec8f0667 | 598 | c = createClient(REDIS_REPLY_ARRAY); |
1cd3c1e0 PN |
599 | len = redisFormatCommand(&cmd,"LRANGE mylist 0 449"); |
600 | c->obuf = sdsnewlen(cmd,len); | |
601 | free(cmd); | |
cc30e368 | 602 | createMissingClients(c); |
603 | aeMain(config.el); | |
ed0dd554 | 604 | endBenchmark(); |
cc30e368 | 605 | |
ed0dd554 | 606 | prepareForBenchmark("LRANGE (first 600 elements)"); |
ec8f0667 | 607 | c = createClient(REDIS_REPLY_ARRAY); |
1cd3c1e0 PN |
608 | len = redisFormatCommand(&cmd,"LRANGE mylist 0 599"); |
609 | c->obuf = sdsnewlen(cmd,len); | |
610 | free(cmd); | |
cc30e368 | 611 | createMissingClients(c); |
612 | aeMain(config.el); | |
ed0dd554 | 613 | endBenchmark(); |
cc30e368 | 614 | |
ed9b544e | 615 | printf("\n"); |
616 | } while(config.loop); | |
617 | ||
618 | return 0; | |
619 | } |