Skip to content

Commit 2be6a2f

Browse files
[add] Added support for redis-benchmark -x option (#256)
1 parent 76e9b94 commit 2be6a2f

File tree

7 files changed

+76
-2
lines changed

7 files changed

+76
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redisbench-admin"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
description = "Redis benchmark run helper. A wrapper around Redis and Redis Modules benchmark tools ( ftsb_redisearch, memtier_benchmark, redis-benchmark, aibench, etc... )."
55
authors = ["filipecosta90 <[email protected]>","Redis Performance Group <[email protected]>"]
66
readme = "README.md"

redisbench_admin/run/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def prepare_benchmark_parameters_specif_tooling(
123123
server_plaintext_port,
124124
entry,
125125
cluster_api_enabled,
126+
current_workdir,
126127
)
127128
if isremote is True:
128129
redirect_file = "> {}".format(remote_results_file)

redisbench_admin/run/redis_benchmark/redis_benchmark.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import csv
88
import logging
9+
import os
910
import re
1011
import shlex
1112
import subprocess
@@ -50,6 +51,7 @@ def prepare_redis_benchmark_command(
5051
server_plaintext_port: object,
5152
benchmark_config: object,
5253
cluster_api_enabled: bool,
54+
current_workdir,
5355
):
5456
"""
5557
Prepares redis-benchmark command parameters
@@ -63,13 +65,16 @@ def prepare_redis_benchmark_command(
6365
command_arr = [executable_path]
6466
command_arr.extend(["-h", "{}".format(server_private_ip)])
6567
command_arr.extend(["-p", "{}".format(server_plaintext_port)])
68+
if current_workdir is None:
69+
current_workdir = os.path.abspath(".")
6670

6771
# we need the csv output
6872
command_arr.extend(["--csv", "-e"])
6973
last_append = None
7074
last_str = ""
7175
if cluster_api_enabled:
7276
command_arr.extend(["--cluster"])
77+
minus_x = None
7378
for k in benchmark_config["parameters"]:
7479
if "clients" in k:
7580
command_arr.extend(["-c", "{}".format(k["clients"])])
@@ -81,12 +86,21 @@ def prepare_redis_benchmark_command(
8186
command_arr.extend(["-P", "{}".format(k["pipeline"])])
8287
if "keyspacelen" in k:
8388
command_arr.extend(["-r", "{}".format(k["keyspacelen"])])
89+
if "r" in k:
90+
command_arr.extend(["-r", "{}".format(k["r"])])
8491
if "size" in k:
8592
command_arr.extend(["-d", "{}".format(k["size"])])
93+
if "x" in k:
94+
with open("{}/{}".format(current_workdir, k["x"]), "r") as fd:
95+
minus_x = fd.read()
8696
# if we have the command keywork then it needs to be at the end of args
8797
if "command" in k:
8898
last_str = k["command"]
8999
last_append = shlex.split(k["command"])
100+
101+
if minus_x is not None:
102+
last_str += " '{}'".format(minus_x)
103+
last_append.append(minus_x)
90104
command_str = " ".join(command_arr)
91105
if last_append is not None:
92106
command_arr.extend(last_append)

tests/test_data/pass-jsonsl-yahoo2.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 0.2
2+
name: "json_set_10k_docs_yahoo2"
3+
remote:
4+
- type: oss-standalone
5+
- setup: redisearch-m5d
6+
clientconfig:
7+
- tool: redis-benchmark
8+
- min-tool-version: "6.2.0"
9+
- parameters:
10+
- clients: 16
11+
- requests: 50000
12+
- threads: 2
13+
- pipeline: 1
14+
- command: 'SET __rand_int__'
15+
- r: 1000
16+
- x: "./tests/test_data/pass-jsonsl-yahoo2.json"

tests/test_redis_benchmark.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,31 @@ def test_prepare_redis_benchmark_command():
2323
)
2424

2525

26+
def test_prepare_redis_benchmark_command_x():
27+
with open("./tests/test_data/redis-benchmark-json.yml", "r") as yml_file:
28+
benchmark_config = yaml.safe_load(yml_file)
29+
for k in benchmark_config["clientconfig"]:
30+
if "parameters" in k:
31+
command_arr, command_str = prepare_redis_benchmark_command(
32+
"redis-benchmark",
33+
"localhost",
34+
"6380",
35+
k,
36+
False,
37+
"./tests/test_data/",
38+
)
39+
assert command_str.startswith(
40+
"redis-benchmark -h localhost -p 6380 --csv -e -c 16 -n 5000000 --threads 2 -P 1 -r 1000000 JSON.SET jsonsl-1 $ '"
41+
)
42+
43+
2644
def test_prepare_redis_benchmark_command():
2745
with open("./tests/test_data/redis-benchmark2.yml", "r") as yml_file:
2846
benchmark_config = yaml.safe_load(yml_file)
2947
for k in benchmark_config["clientconfig"]:
3048
if "parameters" in k:
3149
command_arr, command_str = prepare_redis_benchmark_command(
32-
"redis-benchmark", "localhost", "6380", k, False
50+
"redis-benchmark", "localhost", "6380", k, False, None
3351
)
3452
assert (
3553
command_str

tests/test_run_local.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,30 @@ def test_datasink_profile_tabular_data():
102102
pass
103103

104104

105+
def test_run_local_command_logic_redis_benchmark():
106+
parser = argparse.ArgumentParser(
107+
description="test",
108+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
109+
)
110+
parser = create_run_local_arguments(parser)
111+
args = parser.parse_args(
112+
args=[
113+
"--test",
114+
"./tests/test_data/redis-benchmark-json.yml",
115+
"--keep_env_and_topo",
116+
]
117+
)
118+
try:
119+
run_local_command_logic(args, "tool", "v0")
120+
except SystemExit as e:
121+
assert e.code == 0
122+
123+
r = redis.StrictRedis()
124+
total_keys = r.info("keyspace")["db0"]["keys"]
125+
r.shutdown(nosave=True)
126+
assert total_keys == 1000
127+
128+
105129
def test_run_local_command_logic():
106130
parser = argparse.ArgumentParser(
107131
description="test",

0 commit comments

Comments
 (0)