summaryrefslogtreecommitdiff
path: root/src/redis-benchmark.c
diff options
context:
space:
mode:
authorfilipe oliveira <filipecosta.90@gmail.com>2020-10-26 06:04:59 +0000
committerGitHub <noreply@github.com>2020-10-26 08:04:59 +0200
commit01acfa71ca972a79d215160104fad5f8e6e824af (patch)
tree8f85a6ab17485b4ff7d66bd5065f50ac77fc961a /src/redis-benchmark.c
parentd2af0f25be788ebe47b55ef82d494e0b95860f1f (diff)
downloadredis-01acfa71ca972a79d215160104fad5f8e6e824af.tar.gz
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 <oran@redislabs.com>
Diffstat (limited to 'src/redis-benchmark.c')
-rw-r--r--src/redis-benchmark.c29
1 files changed, 26 insertions, 3 deletions
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 <stdio.h>
#include <string.h>
@@ -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 <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"
+" -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"