]> git.saurik.com Git - redis.git/blobdiff - benchmark.c
EXPIRE tests
[redis.git] / benchmark.c
index a933eba9c48ca4c2ccb0628548944d40f01d6b74..2994186bab09d9d96c222b121eab65dd408f26c5 100644 (file)
@@ -59,6 +59,7 @@
 #define REDIS_NOTUSED(V) ((void) V)
 
 static struct config {
+    int debug;
     int numclients;
     int requests;
     int liveclients;
@@ -86,6 +87,7 @@ typedef struct _client {
     sds ibuf;
     int mbulk;          /* Number of elements in an mbulk reply */
     int readlen;        /* readlen == -1 means read a single line */
+    int totreceived;
     unsigned int written;        /* bytes of 'obuf' already written */
     int replytype;
     long long start;    /* start time in milliseconds */
@@ -137,9 +139,11 @@ static void resetClient(client c) {
     aeCreateFileEvent(config.el,c->fd, AE_WRITABLE,writeHandler,c,NULL);
     sdsfree(c->ibuf);
     c->ibuf = sdsempty();
-    c->readlen = (c->replytype == REPLY_BULK) ? -1 : 0;
+    c->readlen = (c->replytype == REPLY_BULK ||
+                  c->replytype == REPLY_MBULK) ? -1 : 0;
     c->mbulk = -1;
     c->written = 0;
+    c->totreceived = 0;
     c->state = CLIENT_SENDQUERY;
     c->start = mstime();
     createMissingClients(c);
@@ -173,12 +177,18 @@ static void prepareClientForReply(client c, int type) {
 }
 
 static void clientDone(client c) {
+    static int last_tot_received = 1;
+
     long long latency;
     config.donerequests ++;
     latency = mstime() - c->start;
     if (latency > MAX_LATENCY) latency = MAX_LATENCY;
     config.latency[latency]++;
 
+    if (config.debug && last_tot_received != c->totreceived) {
+        printf("Tot bytes received: %d\n", c->totreceived);
+        last_tot_received = c->totreceived;
+    }
     if (config.donerequests == config.requests) {
         freeClient(c);
         aeStop(config.el);
@@ -215,6 +225,7 @@ static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask)
         freeClient(c);
         return;
     }
+    c->totreceived += nread;
     c->ibuf = sdscatlen(c->ibuf,buf,nread);
 
 processdata:
@@ -238,6 +249,7 @@ processdata:
                 *p = '\0';
                 *(p-1) = '\0';
                 c->readlen = atoi(c->ibuf+1)+2;
+                // printf("BULK ATOI: %s\n", c->ibuf+1);
                 /* Handle null bulk reply "$-1" */
                 if (c->readlen-2 == -1) {
                     clientDone(c);
@@ -258,6 +270,7 @@ processdata:
                     clientDone(c);
                     return;
                 }
+                // printf("%p) %d elements list\n", c, c->mbulk);
                 /* Leave all the rest in the input buffer */
                 c->ibuf = sdsrange(c->ibuf,(p-c->ibuf)+1,-1);
                 goto processdata;
@@ -273,9 +286,14 @@ processdata:
          (c->replytype == REPLY_BULK)) && c->readlen != -1 &&
           (unsigned)c->readlen <= sdslen(c->ibuf))
     {
+        // printf("BULKSTATUS mbulk:%d readlen:%d sdslen:%d\n",
+        //    c->mbulk,c->readlen,sdslen(c->ibuf));
         if (c->replytype == REPLY_BULK) {
             clientDone(c);
         } else if (c->replytype == REPLY_MBULK) {
+            // printf("%p) %d (%d)) ",c, c->mbulk, c->readlen);
+            // fwrite(c->ibuf,c->readlen,1,stdout);
+            // printf("\n");
             if (--c->mbulk == 0) {
                 clientDone(c);
             } else {
@@ -332,6 +350,7 @@ static client createClient(void) {
     c->mbulk = -1;
     c->readlen = 0;
     c->written = 0;
+    c->totreceived = 0;
     c->state = CLIENT_CONNECTING;
     aeCreateFileEvent(config.el, c->fd, AE_WRITABLE, writeHandler, c, NULL);
     config.liveclients++;
@@ -346,9 +365,7 @@ static void createMissingClients(client c) {
         sdsfree(new->obuf);
         new->obuf = sdsdup(c->obuf);
         if (config.randomkeys) randomizeClientKey(c);
-        new->replytype = c->replytype;
-        if (c->replytype == REPLY_BULK)
-            new->readlen = -1;
+        prepareClientForReply(new,c->replytype);
     }
 }
 
@@ -432,6 +449,8 @@ void parseOptions(int argc, char **argv) {
             config.quiet = 1;
         } else if (!strcmp(argv[i],"-l")) {
             config.loop = 1;
+        } else if (!strcmp(argv[i],"-D")) {
+            config.debug = 1;
         } else {
             printf("Wrong option '%s' or option argument missing\n\n",argv[i]);
             printf("Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]\n\n");
@@ -450,6 +469,7 @@ void parseOptions(int argc, char **argv) {
             printf("  range will be allowed.\n");
             printf(" -q                 Quiet. Just show query/sec values\n");
             printf(" -l                 Loop. Run the tests forever\n");
+            printf(" -D                 Debug mode. more verbose.\n");
             exit(1);
         }
     }
@@ -461,6 +481,7 @@ int main(int argc, char **argv) {
     signal(SIGHUP, SIG_IGN);
     signal(SIGPIPE, SIG_IGN);
 
+    config.debug = 0;
     config.numclients = 50;
     config.requests = 10000;
     config.liveclients = 0;