Skip to content

Commit 5130d91

Browse files
[add] Added run-local runner (#42)
1 parent c2ab4ca commit 5130d91

File tree

10 files changed

+303
-518
lines changed

10 files changed

+303
-518
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redisbench-admin"
3-
version = "0.1.41"
3+
version = "0.1.42"
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]>"]
66
readme = "README.md"

redisbench_admin/cli.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import logging
23
import sys
34

45
# import toml
@@ -13,6 +14,8 @@
1314
from redisbench_admin.extract.extract import extract_command_logic
1415
from redisbench_admin.run.args import create_run_arguments
1516
from redisbench_admin.run.run import run_command_logic
17+
from redisbench_admin.run_local.args import create_run_local_arguments
18+
from redisbench_admin.run_local.run_local import run_local_command_logic
1619

1720

1821
def populate_with_poetry_data():
@@ -29,6 +32,12 @@ def populate_with_poetry_data():
2932

3033
return project_name, project_description, project_version
3134

35+
# logging settings
36+
logging.basicConfig(
37+
format="%(asctime)s %(levelname)-4s %(message)s",
38+
level=logging.INFO,
39+
datefmt="%Y-%m-%d %H:%M:%S",
40+
)
3241

3342
def main():
3443
tool = None
@@ -53,6 +62,8 @@ def main():
5362

5463
if requested_tool == "run":
5564
parser = create_run_arguments(parser)
65+
elif requested_tool == "run-local":
66+
parser = create_run_local_arguments(parser)
5667
elif requested_tool == "extract":
5768
parser = create_extract_arguments(parser)
5869
elif requested_tool == "compare":
@@ -66,7 +77,7 @@ def main():
6677
print_help(project_name, project_version)
6778
sys.exit(0)
6879
else:
69-
valid_tool_options = ["run", "export", "compare", "retrieve"]
80+
valid_tool_options = ["run", "run-local", "export", "compare", "retrieve"]
7081
print_invalid_tool_option(requested_tool, valid_tool_options)
7182
sys.exit(1)
7283

@@ -75,6 +86,8 @@ def main():
7586

7687
if requested_tool == "run":
7788
run_command_logic(args)
89+
if requested_tool == "run-local":
90+
run_local_command_logic(args)
7891
if requested_tool == "compare":
7992
compare_command_logic(args)
8093
if requested_tool == "export":

redisbench_admin/run/args.py

+4-89
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,20 @@
11
def create_run_arguments(parser):
22
parser.add_argument(
3-
"--benchmark-config-file",
3+
"--tool",
44
type=str,
55
required=True,
6-
help="benchmark config file to read instructions from. can be a local file or a remote link",
6+
help="benchmark tool to use",
77
)
88
parser.add_argument(
9-
"--workers",
10-
type=str,
11-
default=0,
12-
help="number of workers to use during the benchark. If set to 0 it will auto adjust based on the machine number of VCPUs",
13-
)
14-
parser.add_argument(
15-
"--run-only-steps",
16-
type=str,
17-
default="",
18-
help="Comma separated list of use-case steps to run. By default it will run all specified steps.",
19-
)
20-
parser.add_argument(
21-
"--repetitions", type=int, default=1, help="number of repetitions to run"
22-
)
23-
parser.add_argument(
24-
"--benchmark-requests",
25-
type=int,
26-
default=0,
27-
help="Number of total requests to issue (0 = all of the present in input file)",
28-
)
29-
parser.add_argument(
30-
"--s3-bucket-name",
31-
type=str,
32-
default="benchmarks.redislabs",
33-
help="S3 bucket name.",
34-
)
35-
parser.add_argument(
36-
"--upload-results-s3",
37-
default=False,
38-
action="store_true",
39-
help="uploads the result files and configuration file to public benchmarks.redislabs bucket. Proper credentials are required",
40-
)
41-
parser.add_argument(
42-
"--redis-url",
43-
type=str,
44-
default="redis://localhost:6379",
45-
help="The url for Redis connection",
46-
)
47-
parser.add_argument(
48-
"--deployment-type",
49-
type=str,
50-
default="docker-oss",
51-
help="one of docker-oss,docker-oss-cluster,docker-enterprise,oss,oss-cluster,enterprise",
52-
)
53-
parser.add_argument(
54-
"--deployment-shards",
55-
type=int,
56-
default=1,
57-
help="number of database shards used in the deployment",
58-
)
59-
parser.add_argument(
60-
"--pipeline", type=int, default=1, help="pipeline requests to Redis"
61-
)
62-
parser.add_argument(
63-
"--skip-teardown-commands",
64-
default=False,
65-
action="store_true",
66-
help="If enabled will skip any teardown commands.",
67-
)
68-
parser.add_argument(
69-
"--skip-setup-commands",
70-
default=False,
71-
action="store_true",
72-
help="If enabled will skip any setup commands.",
73-
)
74-
parser.add_argument(
75-
"--continue-on-error",
9+
"--remote",
7610
default=False,
7711
action="store_true",
78-
help="If enabled will continue on Redis ERR replies and only print the message.",
79-
)
80-
parser.add_argument(
81-
"--cluster-mode",
82-
default=False,
83-
action="store_true",
84-
help="Run client in cluster mode",
85-
)
86-
parser.add_argument(
87-
"--max-rps",
88-
type=int,
89-
default=0,
90-
help="enable limiting the rate of queries per second, 0 = no limit. "
91-
+ "By default no limit is specified and the binaries will stress the DB up to the maximum.",
12+
help="run the benchmark in remote mode",
9213
)
9314
parser.add_argument(
9415
"--output-file-prefix",
9516
type=str,
9617
default="",
9718
help="prefix to quickly tag some files",
9819
)
99-
parser.add_argument(
100-
"--requests",
101-
type=int,
102-
default=0,
103-
help="Number of total requests to issue (0 = all of the present in input file).",
104-
)
10520
return parser
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import csv
2+
import logging
3+
import shlex
4+
5+
6+
def redis_benchmark_from_stdout_csv_to_json(stdout, start_time, start_time_str):
7+
results_dict = {"Tests": {}, "StartTime": int(start_time.strftime("%s")),
8+
"StartTimeHuman": start_time_str}
9+
csv_data = list(csv.reader(stdout.decode('ascii').splitlines(), delimiter=","))
10+
header = csv_data[0]
11+
for row in csv_data[1:]:
12+
test_name = row[0]
13+
results_dict["Tests"][test_name] = {}
14+
for pos, value in enumerate(row[1:]):
15+
results_dict["Tests"][test_name][header[pos + 1]] = value
16+
return results_dict
17+
18+
19+
def prepareRedisBenchmarkCommand(
20+
executable_path: str,
21+
server_private_ip: object,
22+
server_plaintext_port: object,
23+
benchmark_config: object,
24+
) -> str:
25+
"""
26+
Prepares redis-benchmark command parameters
27+
:param server_private_ip:
28+
:param server_plaintext_port:
29+
:param benchmark_config:
30+
:return: string containing the required command to run the benchmark given the configurations
31+
"""
32+
queries_str = [executable_path]
33+
queries_str.extend(["-h", "{}".format(server_private_ip)])
34+
queries_str.extend(["-p", "{}".format(server_plaintext_port)])
35+
36+
# we need the csv output
37+
queries_str.extend(["--csv", "-e"])
38+
last_append = None
39+
for k in benchmark_config["parameters"]:
40+
if "clients" in k:
41+
queries_str.extend(["-c", "{}".format(k["clients"])])
42+
if "requests" in k:
43+
queries_str.extend(["-n", "{}".format(k["requests"])])
44+
if "threads" in k:
45+
queries_str.extend(["--threads", "{}".format(k["threads"])])
46+
if "pipeline" in k:
47+
queries_str.extend(["-P", "{}".format(k["pipeline"])])
48+
# if we have the command keywork then it needs to be at the end of args
49+
if "command" in k:
50+
last_append = shlex.split(k["command"])
51+
if last_append is not None:
52+
queries_str.extend(last_append)
53+
logging.info(
54+
"Running the benchmark with the following parameters: {}".format(
55+
" ".join(queries_str)
56+
)
57+
)
58+
return queries_str

0 commit comments

Comments
 (0)