Skip to content

Commit f1f1dd0

Browse files
Fixed total shards cpu usage computation when shard info is not present (#316)
* Fixed total shards cpu usage computation when shard info is not present * Bumping version from 0.7.13 to 0.7.14
1 parent ba80720 commit f1f1dd0

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
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.7.13"
3+
version = "0.7.14"
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/ann/pkg

Submodule pkg updated 1 file

redisbench_admin/run/metrics.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,23 @@ def from_info_to_overall_shard_cpu(benchmark_cpu_stats):
135135
total_avg_cpu_pct = 0.0
136136
res = {}
137137
for shard_n, cpu_stats_arr in benchmark_cpu_stats.items():
138+
avg_cpu_pct = None
138139
# we need at least 2 elements to compute the cpu usage
139-
if len(cpu_stats_arr) < 2:
140-
avg_cpu_pct = None
141-
else:
142-
start_ts_micros = cpu_stats_arr[0]["server_time_usec"]
143-
start_total_cpu = get_total_cpu(cpu_stats_arr[0])
144-
end_ts_micros = cpu_stats_arr[len(cpu_stats_arr) - 1]["server_time_usec"]
145-
end_total_cpu = get_total_cpu(cpu_stats_arr[len(cpu_stats_arr) - 1])
146-
total_secs = (end_ts_micros - start_ts_micros) / 1000000
147-
total_cpu_usage = end_total_cpu - start_total_cpu
148-
avg_cpu_pct = 100.0 * (total_cpu_usage / total_secs)
140+
if len(cpu_stats_arr) >= 2:
141+
stats_start_pos = cpu_stats_arr[0]
142+
stats_end_pos = cpu_stats_arr[len(cpu_stats_arr) - 1]
143+
if (
144+
"server_time_usec" in stats_end_pos
145+
and "server_time_usec" in stats_start_pos
146+
):
147+
start_ts_micros = stats_start_pos["server_time_usec"]
148+
end_ts_micros = stats_end_pos["server_time_usec"]
149+
start_total_cpu = get_total_cpu(stats_start_pos)
150+
end_total_cpu = get_total_cpu(stats_end_pos)
151+
total_secs = (end_ts_micros - start_ts_micros) / 1000000
152+
total_cpu_usage = end_total_cpu - start_total_cpu
153+
avg_cpu_pct = 100.0 * (total_cpu_usage / total_secs)
154+
149155
res[shard_n] = avg_cpu_pct
150156
if avg_cpu_pct is not None:
151157
total_avg_cpu_pct += avg_cpu_pct

redisbench_admin/run_remote/run_remote.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,16 @@ def run_remote_command_logic(args, project_name, project_version):
566566
) = from_info_to_overall_shard_cpu(
567567
redisbench_admin.run.metrics.BENCHMARK_CPU_STATS_GLOBAL
568568
)
569-
logging.info(
570-
"Total CPU usage ({:.3f} %)".format(
569+
if total_shards_cpu_usage is None:
570+
total_shards_cpu_usage_str = "n/a"
571+
else:
572+
total_shards_cpu_usage_str = "{:.3f}".format(
571573
total_shards_cpu_usage
572574
)
575+
logging.info(
576+
"Total CPU usage ({} %)".format(
577+
total_shards_cpu_usage_str
578+
)
573579
)
574580

575581
if remote_run_result is False:
@@ -610,9 +616,10 @@ def run_remote_command_logic(args, project_name, project_version):
610616
]
611617
},
612618
)
613-
overall_end_time_metrics[
614-
"total_shards_used_cpu_pct"
615-
] = total_shards_cpu_usage
619+
if total_shards_cpu_usage is not None:
620+
overall_end_time_metrics[
621+
"total_shards_used_cpu_pct"
622+
] = total_shards_cpu_usage
616623
expire_ms = 7 * 24 * 60 * 60 * 1000
617624
export_redis_metrics(
618625
artifact_version,

0 commit comments

Comments
 (0)