summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHassaan Khan <hqkhan2008@gmail.com>2023-05-02 09:20:38 -0400
committerGitHub <noreply@github.com>2023-05-02 16:20:38 +0300
commit8163e816fe9b1ef7f1a904d862f6e2e24bc19713 (patch)
tree0d42a85c7d7f8ac9714414b5f673f94b374c42f9
parentf32d1817e3b133d8e754304ef745e4d40661af24 (diff)
downloadredis-8163e816fe9b1ef7f1a904d862f6e2e24bc19713.tar.gz
[redis-benchmark] Adding --seed option to seed the RNG (#11945)
Adds ability to set the random seed so that more consistent repeatable benchmarks are possible. Example usage: Adding 2 hash items ``` src/redis-benchmark -r 100 -n 2 --seed 250 hset myhash:__rand_int__ age __rand_int__ ``` Monitor: 1st benchmark invocation: ``` 1679332814.824357 [0 127.0.0.1:36686] "hset" "myhash:000000000022" "age" "000000000069" 1679332814.824404 [0 127.0.0.1:36690] "hset" "myhash:000000000007" "age" "000000000043" ``` 2nd benchmark invocation: ``` 1679332814.824357 [0 127.0.0.1:36686] "hset" "myhash:000000000022" "age" "000000000069" 1679332814.824404 [0 127.0.0.1:36690] "hset" "myhash:000000000007" "age" "000000000043" ```
-rw-r--r--src/redis-benchmark.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c
index 5e80de076..95f54539c 100644
--- a/src/redis-benchmark.c
+++ b/src/redis-benchmark.c
@@ -1496,6 +1496,11 @@ int parseOptions(int argc, char **argv) {
fprintf(stderr,
"WARNING: -e option has no effect. "
"We now immediately exit on error to avoid false results.\n");
+ } else if (!strcmp(argv[i],"--seed")) {
+ if (lastarg) goto invalid;
+ int rand_seed = atoi(argv[++i]);
+ srandom(rand_seed);
+ init_genrand64(rand_seed);
} else if (!strcmp(argv[i],"-t")) {
if (lastarg) goto invalid;
/* We get the list of tests to run as a string in the form
@@ -1641,7 +1646,8 @@ usage:
" The -t option is ignored if a specific command is supplied\n"
" on the command line.\n"
" -I Idle mode. Just open N idle connections and wait.\n"
-" -x Read last argument from STDIN.\n",
+" -x Read last argument from STDIN.\n"
+" --seed <num> Set the seed for random number generator. Default seed is based on time.\n",
tls_usage,
" --help Output this help and exit.\n"
" --version Output version and exit.\n\n"