From 01acfa71ca972a79d215160104fad5f8e6e824af Mon Sep 17 00:00:00 2001 From: filipe oliveira Date: Mon, 26 Oct 2020 06:04:59 +0000 Subject: redis-benchmark: add tests, --version, a minor bug fixes (#7947) - add test suite coverage for redis-benchmark - add --version (similar to what redis-cli has) - fix bug sending more requests than intended when pipeline > 1. - when done sending requests, avoid freeing client in the write handler, in theory before responses are received (probably dead code since the read handler will call clientDone first) Co-authored-by: Oran Agra --- src/redis-benchmark.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/redis-benchmark.c') diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index c17178e85..328f08077 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -29,6 +29,7 @@ */ #include "fmacros.h" +#include "version.h" #include #include @@ -179,6 +180,8 @@ typedef struct redisConfig { } redisConfig; /* Prototypes */ +char *redisGitSHA1(void); +char *redisGitDirty(void); static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask); static void createMissingClients(client c); static benchmarkThread *createBenchmarkThread(int index); @@ -196,6 +199,20 @@ static void updateClusterSlotsConfiguration(); int showThroughput(struct aeEventLoop *eventLoop, long long id, void *clientData); +static sds benchmarkVersion(void) { + sds version; + version = sdscatprintf(sdsempty(), "%s", REDIS_VERSION); + + /* Add git commit and working tree status when available */ + if (strtoll(redisGitSHA1(),NULL,16)) { + version = sdscatprintf(version, " (git:%s", redisGitSHA1()); + if (strtoll(redisGitDirty(),NULL,10)) + version = sdscatprintf(version, "-dirty"); + version = sdscat(version, ")"); + } + return version; +} + /* Dict callbacks */ static uint64_t dictSdsHash(const void *key); static int dictSdsKeyCompare(void *privdata, const void *key1, @@ -577,9 +594,8 @@ static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) { if (c->written == 0) { /* Enforce upper bound to number of requests. */ int requests_issued = 0; - atomicGetIncr(config.requests_issued, requests_issued, 1); + atomicGetIncr(config.requests_issued, requests_issued, config.pipeline); if (requests_issued >= config.requests) { - freeClient(c); return; } @@ -1364,6 +1380,11 @@ int parseOptions(int argc, const char **argv) { if (!strcmp(argv[i],"-c")) { if (lastarg) goto invalid; config.numclients = atoi(argv[++i]); + } else if (!strcmp(argv[i],"-v") || !strcmp(argv[i], "--version")) { + sds version = benchmarkVersion(); + printf("redis-benchmark %s\n", version); + sdsfree(version); + exit(0); } else if (!strcmp(argv[i],"-n")) { if (lastarg) goto invalid; config.requests = atoi(argv[++i]); @@ -1496,7 +1517,9 @@ usage: " -l Loop. Run the tests forever\n" " -t 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" +" -I Idle mode. Just open N idle connections and wait.\n" +" --help Output this help and exit.\n" +" --version Output version and exit.\n\n" "Examples:\n\n" " Run the benchmark with the default configuration against 127.0.0.1:6379:\n" " $ redis-benchmark\n\n" -- cgit v1.2.1