Skip to content
This repository
Browse code

Randomize keys and set start time when first write event fires

  • Loading branch information...
commit 2380388974bd0256e1b123d608940355144e9fd4 1 parent 3c49070
Pieter Noordhuis authored December 23, 2010

Showing 1 changed file with 5 additions and 15 deletions. Show diff stats Hide diff stats

  1. 20  src/redis-benchmark.c
20  src/redis-benchmark.c
@@ -45,10 +45,6 @@
45 45
 #include "adlist.h"
46 46
 #include "zmalloc.h"
47 47
 
48  
-#define CLIENT_CONNECTING 0
49  
-#define CLIENT_SENDQUERY 1
50  
-#define CLIENT_READREPLY 2
51  
-
52 48
 #define REDIS_NOTUSED(V) ((void) V)
53 49
 
54 50
 static struct config {
@@ -78,7 +74,6 @@ static struct config {
78 74
 
79 75
 typedef struct _client {
80 76
     redisContext *context;
81  
-    int state;
82 77
     sds obuf;
83 78
     char *randptr[10]; /* needed for MSET against 10 keys */
84 79
     size_t randlen;
@@ -140,9 +135,6 @@ static void resetClient(client c) {
140 135
     aeDeleteFileEvent(config.el,c->context->fd,AE_READABLE);
141 136
     aeCreateFileEvent(config.el,c->context->fd,AE_WRITABLE,writeHandler,c);
142 137
     c->written = 0;
143  
-    c->state = CLIENT_SENDQUERY;
144  
-    c->start = ustime();
145  
-    c->latency = -1;
146 138
 }
147 139
 
148 140
 static void randomizeClientKey(client c) {
@@ -164,7 +156,6 @@ static void clientDone(client c) {
164 156
     }
165 157
     if (config.keepalive) {
166 158
         resetClient(c);
167  
-        if (config.randomkeys) randomizeClientKey(c);
168 159
     } else {
169 160
         config.liveclients--;
170 161
         createMissingClients(c);
@@ -212,11 +203,13 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
212 203
     REDIS_NOTUSED(fd);
213 204
     REDIS_NOTUSED(mask);
214 205
 
215  
-    if (c->state == CLIENT_CONNECTING) {
216  
-        c->state = CLIENT_SENDQUERY;
  206
+    /* When nothing was written yet, randomize keys and set start time. */
  207
+    if (c->written == 0) {
  208
+        if (config.randomkeys) randomizeClientKey(c);
217 209
         c->start = ustime();
218 210
         c->latency = -1;
219 211
     }
  212
+
220 213
     if (sdslen(c->obuf) > c->written) {
221 214
         void *ptr = c->obuf+c->written;
222 215
         int nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
@@ -230,7 +223,6 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
230 223
         if (sdslen(c->obuf) == c->written) {
231 224
             aeDeleteFileEvent(config.el,c->context->fd,AE_WRITABLE);
232 225
             aeCreateFileEvent(config.el,c->context->fd,AE_READABLE,readHandler,c);
233  
-            c->state = CLIENT_READREPLY;
234 226
         }
235 227
     }
236 228
 }
@@ -250,7 +242,6 @@ static client createClient(char *cmd, int len) {
250 242
             fprintf(stderr,"%s: %s\n",config.hostsocket,c->context->errstr);
251 243
         exit(1);
252 244
     }
253  
-    c->state = CLIENT_CONNECTING;
254 245
     c->obuf = sdsnewlen(cmd,len);
255 246
     c->randlen = 0;
256 247
     c->written = 0;
@@ -278,8 +269,7 @@ static void createMissingClients(client c) {
278 269
     int n = 0;
279 270
 
280 271
     while(config.liveclients < config.numclients) {
281  
-        client new = createClient(c->obuf,sdslen(c->obuf));
282  
-        if (config.randomkeys) randomizeClientKey(new);
  272
+        createClient(c->obuf,sdslen(c->obuf));
283 273
 
284 274
         /* Listen backlog is quite limited on most systems */
285 275
         if (++n > 64) {

0 notes on commit 2380388

Please sign in to comment.
Something went wrong with that request. Please try again.