X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/192fc3376a0712e69e638b087c82c7e34f698f4d..f4aa600b996c605b4e2109d0f80cb14a0c14513b:/src/redis-benchmark.c diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 297ecc6c..dcc13286 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -71,6 +71,7 @@ static struct config { aeEventLoop *el; char *hostip; int hostport; + char *hostsocket; int keepalive; long long start; long long totlatency; @@ -359,7 +360,11 @@ static client createClient(void) { client c = zmalloc(sizeof(struct _client)); char err[ANET_ERR_LEN]; - c->fd = anetTcpNonBlockConnect(err,config.hostip,config.hostport); + if (config.hostsocket == NULL) + c->fd = anetTcpNonBlockConnect(err,config.hostip,config.hostport); + else + c->fd = anetUnixNonBlockConnect(err,config.hostsocket); + if (c->fd == ANET_ERR) { zfree(c); fprintf(stderr,"Connect: %s\n",err); @@ -455,6 +460,9 @@ void parseOptions(int argc, char **argv) { } else if (!strcmp(argv[i],"-p") && !lastarg) { config.hostport = atoi(argv[i+1]); i++; + } else if (!strcmp(argv[i],"-s") && !lastarg) { + config.hostsocket = argv[i+1]; + i++; } else if (!strcmp(argv[i],"-d") && !lastarg) { config.datasize = atoi(argv[i+1]); i++; @@ -478,7 +486,8 @@ void parseOptions(int argc, char **argv) { printf("Wrong option '%s' or option argument missing\n\n",argv[i]); printf("Usage: redis-benchmark [-h ] [-p ] [-c ] [-n [-k ]\n\n"); printf(" -h Server hostname (default 127.0.0.1)\n"); - printf(" -p Server port (default 6379)\n"); + printf(" -p Server port (default 6379)\n"); + printf(" -s Server socket (overrides host and port)\n"); printf(" -c Number of parallel connections (default 50)\n"); printf(" -n Total number of requests (default 10000)\n"); printf(" -d Data size of SET/GET value in bytes (default 2)\n"); @@ -537,6 +546,7 @@ int main(int argc, char **argv) { config.hostip = "127.0.0.1"; config.hostport = 6379; + config.hostsocket = NULL; parseOptions(argc,argv); @@ -575,10 +585,28 @@ int main(int argc, char **argv) { aeMain(config.el); endBenchmark(); + prepareForBenchmark("MSET (10 keys, multi bulk)"); + c = createClient(); + if (!c) exit(1); + c->obuf = sdscatprintf(c->obuf,"*%d\r\n$4\r\nMSET\r\n", 11); + { + int i; + char *data = zmalloc(config.datasize+2); + memset(data,'x',config.datasize); + for (i = 0; i < 10; i++) { + c->obuf = sdscatprintf(c->obuf,"$%d\r\n%s\r\n",config.datasize,data); + } + zfree(data); + } + prepareClientForReply(c,REPLY_RETCODE); + createMissingClients(c); + aeMain(config.el); + endBenchmark(); + prepareForBenchmark("SET"); c = createClient(); if (!c) exit(1); - c->obuf = sdscatprintf(c->obuf,"SET foo_rand000000000000 %d\r\n",config.datasize); + c->obuf = sdscat(c->obuf,"SET foo_rand000000000000 "); { char *data = zmalloc(config.datasize+2); memset(data,'x',config.datasize); @@ -612,7 +640,7 @@ int main(int argc, char **argv) { prepareForBenchmark("LPUSH"); c = createClient(); if (!c) exit(1); - c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n"); + c->obuf = sdscat(c->obuf,"LPUSH mylist bar\r\n"); prepareClientForReply(c,REPLY_INT); createMissingClients(c); aeMain(config.el); @@ -630,7 +658,7 @@ int main(int argc, char **argv) { prepareForBenchmark("SADD"); c = createClient(); if (!c) exit(1); - c->obuf = sdscat(c->obuf,"SADD myset 24\r\ncounter_rand000000000000\r\n"); + c->obuf = sdscat(c->obuf,"SADD myset counter_rand000000000000\r\n"); prepareClientForReply(c,REPLY_RETCODE); createMissingClients(c); aeMain(config.el); @@ -648,7 +676,7 @@ int main(int argc, char **argv) { prepareForBenchmark("LPUSH (again, in order to bench LRANGE)"); c = createClient(); if (!c) exit(1); - c->obuf = sdscat(c->obuf,"LPUSH mylist 3\r\nbar\r\n"); + c->obuf = sdscat(c->obuf,"LPUSH mylist bar\r\n"); prepareClientForReply(c,REPLY_RETCODE); createMissingClients(c); aeMain(config.el);