Skip to content

Report per-run means in the --run-count AGGREGATED AVERAGE section - #757

Merged
fcostaoliveira merged 6 commits into
masterfrom
fix/703-aggregated-average
Oct 17, 2026
Merged

fcostaoliveira merged 6 commits into
masterfrom
fix/703-aggregated-average

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --run-count N, the AGGREGATED AVERAGE RESULTS (N runs) section shows its rates and latencies as per-run means, but several other fields in the same section are not means:

  • Runtime: Start time 0 (not a timestamp), and Finish time / Total duration equal to the sum of the run durations (6000 ms for 3 x 2 s runs).
  • Count and Accumulated Latency (Totals and per command), Connection Errors, Unanswered requests, the Per-Key Misses counts, and the CPU cpu_*_seconds / cpu_wall_seconds are all sums over the runs.

Reproduced on master 38dfbaa (-t 1 -c 2 --test-time 2 --run-count 3 --print-all-runs):

RUN #1 ...           Start 1792194755246  Finish 1792194757246  Total duration 2000  Count  70074  Acc 3923  CPU wall 2.0
RUN #2 ...           Start 1792194758249  Finish 1792194760249  Total duration 2000  Count  34848  Acc 3945  CPU wall 2.002
RUN #3 ...           Start 1792194762250  Finish 1792194764250  Total duration 2000  Count  97395  Acc 3915  CPU wall 2.0
AGGREGATED (3 runs)  Start 0              Finish 6000           Total duration 6000  Count 202317  Acc 11784 CPU wall 6.002

Root cause

run_stats::aggregate_average() builds the section with totals::add(), which sums every counter, and then divides only the rate and latency fields by N. It also sets m_start_time = 0 and m_end_time = Σ run durations on purpose. The hit/miss counts are kept summed, and the print paths compute count / ts_diff(start, end), which gives the exact time-weighted rate Σhits / Σduration without truncating small miss counts (0010c1f, #398). The JSON Runtime block then printed that internal interval as if it were a run.

History: in 2.1.0 the section's Total duration was 0, because aggregate_average() never set the times. 0010c1f set them to make Hits/sec non-zero. It first stamped the average duration, and the version that landed in #398 switched to the sum to avoid truncation. The JSON was never adjusted.

Fix

Every value in an "average" section is now a per-run value, consistent with Ops/sec and the latencies. JSON types are unchanged.

  • Counts are per-run means rounded to the nearest integer. The counts stay summed internally, as on master. The object records how many runs it averaged (m_averaged_runs), and print_json() writes them as follows:
    • Each row's Count and Accumulated Latency is round(sum / N).
    • Totals Count and Accumulated Latency are the sum of the rounded rows, so Totals is exactly the sum of its rows. Rounding Totals on its own drifts from that, by up to 4 with 8 --command rows.
    • In Per-Key Misses, when a command's totals are the sum of its key[i] buckets, Total Hits / Total Misses are the sum of the rounded buckets, so they stay the sum of their keys.
    • Connection Errors, Unanswered requests and the Per-Key Misses counts use the same rounded mean, but a non-zero sum never rounds to 0: 1 error or miss over 3 runs prints 1, so it stays visible next to its non-zero /sec rate.
    • A real run's sections print exactly what master prints. result_print_to_json() keeps master's signature, and print_json() passes it the rounded values.
  • Runtime:
    • Total duration = mean run duration.
    • Start time = the first run's start, a real timestamp.
    • Finish time = Start time + Total duration, so Finish - Start == Total duration holds as in every other section.
    • Both the counts and the Runtime switch on m_averaged_runs > 0, so a series cut short after one run is handled the same way.
  • CPU: the CPU seconds (already doubles) are the mean over the runs that reported CPU usage, which is every run on Linux. cores_used and the utilization ratios are unchanged.
  • Rates are unchanged. They still divide summed counts by the summed duration. For --command rows, Hits/sec and Misses/sec are therefore time-weighted (Σcount / Σduration). Ops/sec, KB/sec and the default workload's Hits/Misses/sec remain means of the per-run rates.
  • Section name: the (N runs) header still follows --run-count, so the JSON key is stable. If the series is cut short, the means are over the runs completed (Runs completed). This is documented in the README's new "Repeated runs" section.

The text table has no counts or duration, so it is unchanged. The stderr CPU summary for the AVERAGE shows per-run seconds, the same as the JSON. The stderr miss-rate warning keeps the summed (X misses / Y ops) on purpose: it reports the ratio over the whole series, and #585's tests check those exact sums.

Interactions:

Compatibility note

Values change, types don't. In the AGGREGATED AVERAGE RESULTS section, no keys are added or removed and every value keeps its JSON type. Integers stay integers, so strictly typed consumers (for example Go Count int64) still parse the file. BEST, WORST, RUN #i and ALL STATS are unaffected.

  • Count, Accumulated Latency, Connection Errors, Unanswered requests and the Per-Key Misses counts become rounded per-run means, about 1/N of the old sums. For example, 29659 ops over 3 runs gives "Count": 9886 instead of 29659.
  • CPU seconds, Total duration and Finish time drop by about N, and Start time becomes the first run's start instead of 0.
  • The section's merged HDR histogram (Histogram log format) still holds the samples of all runs, so its encoded total count is about N × Count. This is deliberate: the percentiles come from all samples. It is documented and covered by the --run-count JSON: AGGREGATED AVERAGE Totals percentiles come from an empty histogram #567 test.
  • The AGGREGATED counts are rounded means, so multiplying them by Runs completed only approximates the series totals. Exact totals are the sum of the RUN #i sections (--print-all-runs). The main downstream consumer we checked, redis-benchmarks-specification's defaults.yml, reads only rates and latencies from these files.

Tests

  • test_json_aggregated_duration_and_counts_are_run_mean (--run-count=3 --test-time=2 --print-all-runs) checks:
    • Total duration equals the mean of the run durations (±2 ms) and is close to --test-time.
    • Start time equals RUN pcre required for build #1's start, and Finish - Start == Total duration.
    • Sets and Gets Count are exactly the rounded mean of the per-run counts, integers.
    • Totals Count and Accumulated Latency are exactly the sum of the rows.
    • Unanswered requests is the rounded mean.
    • The CPU block is present on Linux, and its user/sys/total/wall seconds are per-run means.
  • test_json_aggregated_arbitrary_command_counts_are_run_mean (default --command-stats-breakdown=command, 8 type rows) and test_json_aggregated_arbitrary_command_line_counts_are_run_mean (line, 9 rows) both run 9 --command lines of 8 types (two GET lines) with --run-count=2. They check that every row Count is the exact rounded mean, that Totals is exactly the sum of the rows, and that the MGET Per-Key Misses key[i] counts are the rounded means, with each Total exactly the sum of its keys. At 094dd7a, where Total was rounded on its own, those checks failed in 2 of 3 runs, depending on rounding; at e53a23a they passed 5/5.
  • test_json_aggregated_small_count_never_rounds_to_zero: one client sends GET then SET of one key per run, --run-count=3, so only run 1's GET misses. It checks that the AGGREGATED Total Misses / key[0] Misses is 1, not 0, next to a non-zero Misses/sec.
  • test_json_aggregated_unanswered_requests_are_run_mean pauses writes for the whole series, so every run abandons its in-flight SETs, and checks the rounded mean.
  • test_json_aggregated_connection_errors_sec also checks the Connection Errors count.
  • The --run-count 3 interrupt tests in tests_oss_simple_flow.py (SIGINT during, and after, run 1) check that the AGGREGATED Count, Connection Errors and Unanswered requests equal RUN pcre required for build #1's integers, and Accumulated Latency is within 3.
  • test_aggregated_average_totals_histogram (--run-count JSON: AGGREGATED AVERAGE Totals percentiles come from an empty histogram #567) expects Count 4000 per run and a histogram of 2 × Count.

Evidence (--env oss; the table was measured at 094dd7a, the current head e53a23a is on master 3093d17). The four count tests (small-count, both breakdowns, duration):

Binary Result
master 4/4 fail
previous head 10223cf (doubles) 4/4 fail (not integers)
mutant without the never-0 rule only the small-count test fails
mutant with Totals rounded on its own both breakdown tests fail (the duration test only catches it by chance, when its 2-3 row roundings happen to disagree)
fix 4/4 pass, 5/5 loops

With the fix:

  • test_json_output_integrity.py with the two interrupt tests and the --run-count JSON: AGGREGATED AVERAGE Totals percentiles come from an empty histogram #567 test passes 28/28 at e53a23a. test_json_output_integrity.py with test_arbitrary_command_misses.py passes 41/41.
  • tests_oss_simple_flow.py and test_prometheus.py run-count tests, test_hdr_histogram.py and test_miss_rate_tracking.py pass 36/36.
  • test_cpu_stats.py, test_arbitrary_command_misses.py, test_cli_validation_run_count.py and test_cli_validation_count_flags.py pass 55/55.
  • --env oss-cluster --shards-count 3: 3/3.

Affected versions

2.4.0 through 2.5.2 (latest) and master for the summed Total duration / Finish time and Start time 0. Introduced by 0010c1f, landed via 1485147 (#398), first tag 2.4.0. Count / Accumulated Latency / Connection Errors are sums in 2.5.2 and master. 2.1.0 printed 0 for duration and Count in this section.

Fixes #703

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this. The write-up is unusually thorough, and the Runtime part is clearly a bug fix: Start time 0 and a summed Total duration in an "average" section were never right. I went through the C++ and the tests, and I have a few comments, mostly about compatibility.

1. Changing the counts silently is the part I'm least sure about. Keeping the JSON types is the right instinct, and the doubles round shows you already went through this trade-off once. But the semantic change is arguably harder on consumers than a type change. Anything that reads Count / Accumulated Latency / Connection Errors from the AGGREGATED section as a series total won't fail to parse. It will just get numbers about N× smaller, with no signal that anything changed. Our precedent leans toward the less-breaking option when two fixes are viable (PR#212 picked strtod over the "more correct" strtoull, and PR#60 said "make this optional or at least ... minimize risk"). Did you consider a split here: fix Runtime and the CPU seconds, which are plainly wrong today, and leave the counts as sums with a README note? Or add per-run keys next to the existing ones? Checking redis-benchmarks-specification helps, but it's only one consumer.

2. Totals can't be recovered after this. The PR body suggests multiplying by Runs completed to get series totals. With round-to-nearest plus the never-0 floor, that's lossy: 1 error over 3 runs prints 1, and ×3 gives 3. Unless --print-all-runs is on, the section no longer holds the real sum anywhere. If we go ahead with this, I'd at least drop that suggestion from the description/README or qualify it.

3. The section now disagrees with itself. The histogram's encoded count is now N × Count, while every other section keeps count == Count, and you had to change the #567 test to match. Totals is now the sum of the rounded rows, not the rounded mean of the Totals, so it can drift from Ops/sec × Total duration by about one unit per row, more with the floor. Each choice makes sense locally, but together the section has several invariants that hold everywhere except here. I wonder if that's a sign the counts should stay sums (see 1).

4. Per-Key Misses key_hits == t.total_hits check (run_stats.cpp, in print_json()): when do the per-key buckets not add up to the totals? If that only happens for some command shapes, a short comment naming the case would help, because right now it reads like a heuristic. Is the fallback path covered by a test?

5. Nitpicking: CPU seconds are divided by cpu_runs, while the counts and duration are divided by all_stats.size(). That's documented and fine on Linux. Maybe also mention in the code comment that the denominators differ on purpose.

The tests are solid. The fails-on-master / mutant table is the bar PR#364 set, and covering both --command-stats-breakdown paths plus the cut-short series is what I'd have asked for. The integer-division and empty-series edge cases (no run started, m_averaged_runs > 0 with zero duration) look handled. The Runtime fix looks good to merge as is. For the counts, I'd want a maintainer to decide on the compatibility question before this lands, and that may be worth a second look from whoever owns the JSON output contract.

(I'd file this as a comment, not a formal block.)

fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
Review of #757: rounding each averaged count with (x + n/2) / n broke two
things. Totals and every command row were rounded separately, so the
AGGREGATED Totals Count no longer equalled the sum of its rows (off by up
to 4 with 8 --command rows, by 1 on the default workload). And a small
count (1 connection error, unanswered request or miss over 3 runs) printed
0 next to a non-zero /sec rate.

Keep every count summed internally, as before this PR, and write it in
the AGGREGATED section as count / N, a double that reads back exactly
("Count": 9886.333333333334, always with a decimal point). This covers
Count, Accumulated Latency, Connection Errors, Unanswered requests and the
Per-Key Misses counts, while the CPU seconds already were doubles. Totals
again equals the sum of the rows up to float precision. The rounding
helpers, and the divisions of counters the AVERAGE never prints (bytes,
retry counters), are gone.

Tests: Totals Count == sum of 8 --command rows within 1e-6 with
--run-count 2, and per-run means for those rows, the MGET Per-Key Misses
counts, Unanswered requests (writes paused for the whole series) and the
CPU user/sys seconds. README: --command Hits/sec and Misses/sec are
time-weighted, the "(N runs)" header follows --run-count while the means
use the runs completed, and CPU seconds average the runs that reported CPU.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/703-aggregated-average branch from 8503a17 to b202637 Compare October 17, 2026 00:55
@fcostaoliveira

fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Taking your points in order (fixed in b202637):

(a) Compatibility of the counts. The keys stay the same and the values change. That is intended, and it is now spelled out in the PR's compatibility section. An "AGGREGATED AVERAGE" section that reports N-fold totals next to per-run rates misleads every reader, and a consumer that wants series totals can multiply by Runs completed, which is in the same file. Before choosing this we checked the main downstream consumer, redis-benchmarks-specification's defaults.yml. It reads only rates and latencies from these files, not Count or Runtime. If a maintainer prefers the split (Runtime here, counts kept or added under new keys), I'm happy to do that. I'm not doing it pre-emptively.

(b) Histogram total = N × Count. This is deliberate. The section's percentiles come from the merged histogram of all samples, and a histogram cannot be scaled by 1/N exactly. The README "Repeated runs" section documents it, and the #567 test (test_aggregated_average_totals_histogram) now asserts histogram count == N × Count explicitly, so the relationship is pinned rather than just tolerated.

(c) Small counts rounded to 0. Fixed. Nothing is rounded any more. The counts stay summed internally and are written in the AGGREGATED section as the exact mean count / N, as a double ("Count": 9886.3333333333339). A single miss over 3 runs now prints 0.333... next to its non-zero rate. This also restores the invariant that Totals Count is the sum of the command rows; rounding each row separately had broken it, by up to 4 with 8 --command rows. A new test checks it within 1e-6 with 8 commands and --run-count 2. The compat note mentions the type change from integer to fractional numbers.

(d) Duplicated rounding helper. Gone, along with the rounding itself and the divisions of counters the AVERAGE never prints. totals_cmd::aggregate_average() is back to master.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Following up on the updated review (point numbers refer to that comment). Fixed in e204690:

2. JSON type depending on runs completed. Fixed. write_json_count() and the Accumulated Latency branch now key off runs > 0. m_averaged_runs is 0 for a real run, so a --run-count series cut short after its first run writes doubles in the AGGREGATED section, just like a complete series. The --run-count 3 interrupt tests (SIGINT during run 1, and in the pause after it) now assert that the AGGREGATED Count, Accumulated Latency, Connection Errors and Unanswered requests are doubles while RUN #1 keeps integers. Those assertions fail on b202637 and pass with the fix.

3. m_start_time / m_end_time on the average object. The comment on the assignment in aggregate_average() already says these values start at the first run's start and span the summed duration, and that the JSON Runtime prints the mean from them. The header comment on m_averaged_runs says the same. I left them as they are.

4. n in strpbrk(buf, ".eEn"). Dropped. A count divided by a non-zero run count cannot be nan or inf.

Separately, the README example (and my earlier reply) now shows memtier's real output, 9886.3333333333339. memtier falls back to %.17g when %.15g does not round-trip, so the earlier 9886.333333333334 was Python's repr, not what memtier prints.

fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
Review of #757: rounding each averaged count with (x + n/2) / n broke two
things. Totals and every command row were rounded separately, so the
AGGREGATED Totals Count no longer equalled the sum of its rows (off by up
to 4 with 8 --command rows, by 1 on the default workload). And a small
count (1 connection error, unanswered request or miss over 3 runs) printed
0 next to a non-zero /sec rate.

Keep every count summed internally, as before this PR, and write it in
the AGGREGATED section as count / N, a double that reads back exactly
("Count": 9886.333333333334, always with a decimal point). This covers
Count, Accumulated Latency, Connection Errors, Unanswered requests and the
Per-Key Misses counts, while the CPU seconds already were doubles. Totals
again equals the sum of the rows up to float precision. The rounding
helpers, and the divisions of counters the AVERAGE never prints (bytes,
retry counters), are gone.

Tests: Totals Count == sum of 8 --command rows within 1e-6 with
--run-count 2, and per-run means for those rows, the MGET Per-Key Misses
counts, Unanswered requests (writes paused for the whole series) and the
CPU user/sys seconds. README: --command Hits/sec and Misses/sec are
time-weighted, the "(N runs)" header follows --run-count while the means
use the runs completed, and CPU seconds average the runs that reported CPU.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/703-aggregated-average branch 2 times, most recently from 10223cf to 094dd7a Compare October 17, 2026 02:04
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
Review of #757: rounding each averaged count with (x + n/2) / n broke two
things. Totals and every command row were rounded separately, so the
AGGREGATED Totals Count no longer equalled the sum of its rows (off by up
to 4 with 8 --command rows, by 1 on the default workload). And a small
count (1 connection error, unanswered request or miss over 3 runs) printed
0 next to a non-zero /sec rate.

Keep every count summed internally, as before this PR, and write it in
the AGGREGATED section as count / N, a double that reads back exactly
("Count": 9886.333333333334, always with a decimal point). This covers
Count, Accumulated Latency, Connection Errors, Unanswered requests and the
Per-Key Misses counts, while the CPU seconds already were doubles. Totals
again equals the sum of the rows up to float precision. The rounding
helpers, and the divisions of counters the AVERAGE never prints (bytes,
retry counters), are gone.

Tests: Totals Count == sum of 8 --command rows within 1e-6 with
--run-count 2, and per-run means for those rows, the MGET Per-Key Misses
counts, Unanswered requests (writes paused for the whole series) and the
CPU user/sys seconds. README: --command Hits/sec and Misses/sec are
time-weighted, the "(N runs)" header follows --run-count while the means
use the runs completed, and CPU seconds average the runs that reported CPU.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Follow-up on the compatibility point (1). I've switched approaches, in 094dd7a. The AGGREGATED counts are integers again, still as per-run means, so values change, types don't. That resolves the concern about strictly typed consumers: a Go Count int64 failed to parse the whole file on 1000.0, and the less-breaking fix wins here, as in #212.

  • Rows: each row's Count and Accumulated Latency is its per-run mean, rounded to the nearest integer.
  • Totals: Count and Accumulated Latency are the sum of the rounded rows, so Totals is exactly the sum of its rows. The repo asserts that invariant for ALL STATS, and the new tests now assert it for AGGREGATED too, with both --command-stats-breakdown modes.
  • Small counts: Connection Errors, Unanswered requests and the Per-Key Misses counts use the same rounded mean, but a non-zero sum never rounds to 0. 1 miss over 3 runs prints 1, so the zero-count-next-to-a-non-zero-rate case from your earlier comment stays fixed. A new test covers it.
  • CPU seconds: they stay doubles, as they always were.

result_print_to_json() is back to master's signature, and the doubles-printing helpers are gone. The Runtime check now uses m_averaged_runs > 0, consistent with the counts. The README "Repeated runs" section and the PR's compatibility section describe the rounding rules.

fcostaoliveira and others added 6 commits October 17, 2026 03:30
With --run-count N, the AGGREGATED AVERAGE RESULTS section printed its
rates and latencies as per-run means, but its Runtime said Start time 0,
Finish time and Total duration equal to the SUM of the run durations, and
its Count, Accumulated Latency, Connection Errors, Unanswered requests,
Per-Key Misses counts and CPU seconds were sums over the runs too. A
reader of an "average" section takes 6000 ms as the length of an average
2 s run.

aggregate_average() kept the summed duration on purpose: the hit/miss
counts stay summed so that Σhits / Σduration gives the exact time-weighted
rate without truncating small miss counts. Keep that internally, but:

- divide the summed counters (totals and per command) by N, rounded;
- start the section at the first run's start and record N, so the JSON
  Runtime prints the mean run duration, with Finish - Start == Total
  duration as in every other section;
- print the Per-Key Misses counts per run;
- report the CPU and wall seconds per run (the ratios are unchanged).

The JSON keys are unchanged; only the values in the AGGREGATED section
change. Its merged HDR histogram still holds the samples of all runs, so
its encoded count is N x Count. A run that never started still counts as
one of the N runs with zero duration, like its zero Ops/sec. The stderr
miss-rate warning keeps the summed counts, since it reports the ratio over
the whole series. Documented in the README.

Fixes #703

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #757: rounding each averaged count with (x + n/2) / n broke two
things. Totals and every command row were rounded separately, so the
AGGREGATED Totals Count no longer equalled the sum of its rows (off by up
to 4 with 8 --command rows, by 1 on the default workload). And a small
count (1 connection error, unanswered request or miss over 3 runs) printed
0 next to a non-zero /sec rate.

Keep every count summed internally, as before this PR, and write it in
the AGGREGATED section as count / N, a double that reads back exactly
("Count": 9886.333333333334, always with a decimal point). This covers
Count, Accumulated Latency, Connection Errors, Unanswered requests and the
Per-Key Misses counts, while the CPU seconds already were doubles. Totals
again equals the sum of the rows up to float precision. The rounding
helpers, and the divisions of counters the AVERAGE never prints (bytes,
retry counters), are gone.

Tests: Totals Count == sum of 8 --command rows within 1e-6 with
--run-count 2, and per-run means for those rows, the MGET Per-Key Misses
counts, Unanswered requests (writes paused for the whole series) and the
CPU user/sys seconds. README: --command Hits/sec and Misses/sec are
time-weighted, the "(N runs)" header follows --run-count while the means
use the runs completed, and CPU seconds average the runs that reported CPU.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
write_json_count() and the Accumulated Latency branch keyed off runs > 1,
so a --run-count series cut short after its first run (Ctrl+C) printed
the AGGREGATED counts as integers, and a complete series as doubles. The
JSON type depended on the number of runs completed. m_averaged_runs is 0
for a real run, so key off runs > 0.

Assert in the run-count interrupt tests (SIGINT during, and after, run 1
of 3) that the AGGREGATED Count, Accumulated Latency, Connection Errors
and Unanswered requests are doubles while RUN #1 keeps integers. Also
drop the dead 'n' from the decimal-point check, note that per-run
sections keep integer Accumulated Latency, and use memtier's real %.17g
output in the README example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The arbitrary-command count test only ran with
--command-stats-breakdown=line, so the default per-type path in
print_json() was untested: passing 0 instead of m_averaged_runs there
printed summed --command rows next to a mean Totals and no test noticed.
Run it with both breakdowns, over 9 --command lines of 8 types (two GET
lines, which the per-type rows merge).

Also require the CPU block on Linux in the duration test instead of
skipping the CPU checks when it is missing, and warn next to the
assignment that the average's m_end_time is synthetic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Writing the averaged counts as doubles (b202637) changed their JSON type,
and strictly typed consumers fail to parse the whole file on it: a Go
struct with `Count int64` rejects `1000.0`. Keep the per-run means but
write them as integers again, so only the values in the AGGREGATED section
change, not their types:

- each row's Count and Accumulated Latency is its summed count divided by
  the runs, rounded to the nearest integer;
- Totals Count and Accumulated Latency are the sum of the rounded rows, so
  Totals is exactly the sum of its rows (rounding Totals on its own drifts
  from it, by up to 4 with 8 --command rows);
- Connection Errors, Unanswered requests and the Per-Key Misses counts use
  the same rounded mean, but a non-zero sum never rounds to 0, so a single
  error or miss stays visible next to its non-zero /sec rate;
- the CPU seconds stay doubles, as they always were.

result_print_to_json() is back to master's signature: print_json() passes
it the rounded row values and the summed Totals. The Runtime mean-duration
check now uses m_averaged_runs > 0 like the counts.

Tests assert integers again: rows are exactly the rounded mean of the
per-run values, Totals Count and Accumulated Latency exactly the sum of
the rows (both breakdowns, 9 --command lines), 1 miss over 3 runs gives
1 (GET then SET of one key per run, so only run 1 misses), and the
interrupt tests check that a series cut after run 1 reports run 1's
integers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the AGGREGATED Per-Key Misses, Total Hits / Total Misses were rounded
on their own, separately from the key[i] values, so a Total could be one
off the sum of its keys (HMGET Total Misses 17551 vs a key sum of 17550).
When a command's summed totals are the sum of its per-key buckets, write
each Total as the sum of the rounded buckets, like Totals and its rows,
and assert it in the MGET test.

README: Totals can be about one unit per row away from the mean of the
per-run Totals (the never-0 floor and the per-row ms truncation of
Accumulated Latency make half a unit too tight).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/703-aggregated-average branch from 094dd7a to e53a23a Compare October 17, 2026 02:30
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

On point 3 of the updated review: yes, the never-0 floor also applies to a row's Count, and that's intended. A row that had operations never shows Count 0 next to a non-zero Ops/sec. Totals follows the rounded rows by design: Totals Count and Accumulated Latency are the sum of the rows, so Totals is exactly the sum of its rows. Because of the floor and the per-row ms truncation of Accumulated Latency, Totals can be about one unit per row away from the mean of the per-run Totals. The README now says "about one unit per row", where it previously said half a unit.

The Per-Key Misses totals now follow the same rule (e53a23a). When a command's totals are the sum of its key[i] buckets, Total Hits and Total Misses are the sum of the rounded buckets, so they stay equal to the sum of their keys. Before this, an HMGET Total Misses could be one higher than its key sum. The MGET test asserts this.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Addendum to the updated review:

  • Point 2: agreed, the "multiply by Runs completed" suggestion was lossy once the counts are rounded and floored. The PR description now says that this only approximates the series totals, and that exact totals are the sum of the RUN #i sections (--print-all-runs).
  • Point 3: histogram count = N × Count is deliberate. The percentiles come from all the samples, and an HDR histogram can't be scaled by 1/N. It is documented in the README and asserted by the --run-count JSON: AGGREGATED AVERAGE Totals percentiles come from an empty histogram #567 test. Totals vs the rows is answered in my comment above.

@fcostaoliveira
fcostaoliveira merged commit 3fcbfbc into master Oct 17, 2026
129 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--run-count: AGGREGATED AVERAGE RESULTS reports Total duration (and Count) summed over runs, not averaged

1 participant