+
+ return i;
+
+invalid:
+ printf("Invalid option \"%s\" or option argument missing\n\n",argv[i]);
+
+usage:
+ printf(
+"Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]\n\n"
+" -h <hostname> Server hostname (default 127.0.0.1)\n"
+" -p <port> Server port (default 6379)\n"
+" -s <socket> Server socket (overrides host and port)\n"
+" -c <clients> Number of parallel connections (default 50)\n"
+" -n <requests> Total number of requests (default 10000)\n"
+" -d <size> Data size of SET/GET value in bytes (default 2)\n"
+" -k <boolean> 1=keep alive 0=reconnect (default 1)\n"
+" -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD\n"
+" Using this option the benchmark will get/set keys\n"
+" in the form mykey_rand:000000012456 instead of constant\n"
+" keys, the <keyspacelen> argument determines the max\n"
+" number of values for the random number. For instance\n"
+" if set to 10 only rand:000000000000 - rand:000000000009\n"
+" range will be allowed.\n"
+" -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).\n"
+" -q Quiet. Just show query/sec values\n"
+" --csv Output in CSV format\n"
+" -l Loop. Run the tests forever\n"
+" -t <tests> Only run the comma separated list of tests. The test\n"
+" names are the same as the ones produced as output.\n"
+" -I Idle mode. Just open N idle connections and wait.\n\n"
+"Examples:\n\n"
+" Run the benchmark with the default configuration against 127.0.0.1:6379:\n"
+" $ redis-benchmark\n\n"
+" Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:\n"
+" $ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20\n\n"
+" Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:\n"
+" $ redis-benchmark -t set -n 1000000 -r 100000000\n\n"
+" Benchmark 127.0.0.1:6379 for a few commands producing CSV output:\n"
+" $ redis-benchmark -t ping,set,get -n 100000 --csv\n\n"
+" Fill a list with 10000 random elements:\n"
+" $ redis-benchmark -r 10000 -n 10000 lpush mylist ele:rand:000000000000\n\n"
+ );
+ exit(exit_status);
+}
+
+int showThroughput(struct aeEventLoop *eventLoop, long long id, void *clientData) {
+ REDIS_NOTUSED(eventLoop);
+ REDIS_NOTUSED(id);
+ REDIS_NOTUSED(clientData);
+
+ if (config.csv) return 250;
+ float dt = (float)(mstime()-config.start)/1000.0;
+ float rps = (float)config.requests_finished/dt;
+ printf("%s: %.2f\r", config.title, rps);
+ fflush(stdout);
+ return 250; /* every 250ms */
+}
+
+/* Return true if the named test was selected using the -t command line
+ * switch, or if all the tests are selected (no -t passed by user). */
+int test_is_selected(char *name) {
+ char buf[256];
+ int l = strlen(name);
+
+ if (config.tests == NULL) return 1;
+ buf[0] = ',';
+ memcpy(buf+1,name,l);
+ buf[l+1] = ',';
+ buf[l+2] = '\0';
+ return strstr(config.tests,buf) != NULL;