Skip to content

Fix JSON Totals latency precision and add integrity regression tests - #364

Merged
fcostaoliveira merged 1 commit into
redis:masterfrom
filipecosta90:fix/red-191460-json-totals-latency
May 5, 2026
Merged

fcostaoliveira merged 1 commit into
redis:masterfrom
filipecosta90:fix/red-191460-json-totals-latency

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Fix Totals.Latency / Totals.Average Latency in --json-out-file reporting integer-truncated values (e.g. real avg 1.291 ms shown as 1.000; sub-ms shown as 0.000). Root cause: totals::m_latency was unsigned long long, and run_stats::summarize() assigned the averaged double into it. Sets/Gets sections were unaffected because totals_cmd::m_latency is already double.
  • Fix latent typo in totals::add() that conflated m_latency with m_total_latency — harmless before summarize(), corrupted m_total_latency afterwards in the multi-run aggregate path.
  • Make summarize() populate result.m_total_latency from the per-cmd raw latency sum, so BEST RUN, WORST RUN, and AGGREGATED AVERAGE sections carry a correct Accumulated Latency (was 0 in the aggregated path because summarize() only set m_latency).
  • Add regression test tests/test_json_output_integrity.py that pins the invariant Latency == Average Latency == Accumulated / Count for Sets / Gets / Totals across single-run, SET-only, GET-only and multi-run aggregated outputs, plus per-second time-series buckets. The existing total_latency > 0 check did not catch this because the bug surfaced as 1.000 (plausible-looking) rather than 0.

Refs: RED-191460

Test plan

  • OSS_STANDALONE=1 TEST=test_json_output_integrity.py ./tests/run_tests.sh — all 4 new tests pass on the fix; the multi-run test fails on master without the summarize() change, validating it catches both bugs.
  • OSS_STANDALONE=1 TEST=test_scan.py ./tests/run_tests.sh — 15/15 pass (sanity check that unrelated tests still work).
  • Manual verification with reporter's command shape (sub-ms latency): Totals.Latency now matches Accumulated Latency / Count instead of being 0.000.

🤖 Generated with Claude Code


Note

Medium Risk
Changes how Totals latency/accumulated latency are computed and aggregated for --json-out-file, which can affect reported benchmark metrics and downstream consumers. Adds regression tests that may surface previously hidden inconsistencies across multi-run and time-series outputs.

Overview
Fixes incorrect Totals JSON latency reporting by preserving fractional precision (stores totals::m_latency as double) and by computing both average latency and Accumulated Latency from a single summed total_latency_sum in run_stats::summarize().

Corrects multi-run aggregation by summing m_total_latency (not m_latency) in totals::add(), ensuring BEST/WORST/AGGREGATED sections carry consistent accumulated latency.

Adds tests/test_json_output_integrity.py to regression-test the invariant Latency == Average Latency ~= Accumulated Latency / Count across Sets/Gets/Totals, multi-run aggregate sections, and per-second time-series buckets.

Reviewed by Cursor Bugbot for commit 550a695. Bugbot is set up for automated code reviews on this repo. Configure here.

@fcostaoliveira
fcostaoliveira requested a review from paulorsousa May 5, 2026 13:40
The Totals section of --json-out-file reported "Latency" and "Average
Latency" as integer-truncated values. A real average of 1.291 ms came
out as 1.000; sub-millisecond averages came out as 0.000. The Sets and
Gets sections were correct because totals_cmd::m_latency is double; only
the outer totals::m_latency was unsigned long long, and run_stats::summarize
assigned the averaged double into it, truncating fractional milliseconds.

Three changes:

- run_stats_types.h: change totals::m_latency from unsigned long long to
  double so the averaged value survives summarize().

- run_stats_types.cpp: fix a long-standing typo in totals::add() that
  conflated m_latency and m_total_latency. The two fields held the same
  value before summarize() ran, so the typo was harmless on the live
  accumulator path but corrupted m_total_latency once summarize() turned
  m_latency into an average for the multi-run aggregate path.

- run_stats.cpp: have summarize() also write the raw latency sum into
  result.m_total_latency, so the BEST/WORST/AGGREGATED sections produced
  by aggregate_average() carry a correct "Accumulated Latency".

Tests: tests/test_json_output_integrity.py asserts the invariant
Latency == Average Latency == Accumulated / Count for Sets, Gets, Totals
across single-run, SET-only, GET-only and multi-run aggregated outputs,
plus the per-second time-series buckets. The existing total_latency > 0
check was insufficient because the bug surfaced as 1.000 ms (looks
plausible) rather than 0.

Refs: RED-191460

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/red-191460-json-totals-latency branch from 8db6e79 to 550a695 Compare May 5, 2026 13:42
@fcostaoliveira
fcostaoliveira merged commit 7344622 into redis:master May 5, 2026
65 checks passed
@fcostaoliveira
fcostaoliveira deleted the fix/red-191460-json-totals-latency branch May 5, 2026 14:14
@fcostaoliveira fcostaoliveira mentioned this pull request May 5, 2026
4 tasks done
fcostaoliveira added a commit to filipecosta90/memtier_benchmark that referenced this pull request May 5, 2026
…edis#364)

The Totals section of --json-out-file reported "Latency" and "Average
Latency" as integer-truncated values. A real average of 1.291 ms came
out as 1.000; sub-millisecond averages came out as 0.000. The Sets and
Gets sections were correct because totals_cmd::m_latency is double; only
the outer totals::m_latency was unsigned long long, and run_stats::summarize
assigned the averaged double into it, truncating fractional milliseconds.

Three changes:

- run_stats_types.h: change totals::m_latency from unsigned long long to
  double so the averaged value survives summarize().

- run_stats_types.cpp: fix a long-standing typo in totals::add() that
  conflated m_latency and m_total_latency. The two fields held the same
  value before summarize() ran, so the typo was harmless on the live
  accumulator path but corrupted m_total_latency once summarize() turned
  m_latency into an average for the multi-run aggregate path.

- run_stats.cpp: have summarize() also write the raw latency sum into
  result.m_total_latency, so the BEST/WORST/AGGREGATED sections produced
  by aggregate_average() carry a correct "Accumulated Latency".

Tests: tests/test_json_output_integrity.py asserts the invariant
Latency == Average Latency == Accumulated / Count for Sets, Gets, Totals
across single-run, SET-only, GET-only and multi-run aggregated outputs,
plus the per-second time-series buckets. The existing total_latency > 0
check was insufficient because the bug surfaced as 1.000 ms (looks
plausible) rather than 0.

Refs: RED-191460

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
fcostaoliveira added a commit that referenced this pull request May 5, 2026
…364)

The Totals section of --json-out-file reported "Latency" and "Average
Latency" as integer-truncated values. A real average of 1.291 ms came
out as 1.000; sub-millisecond averages came out as 0.000. The Sets and
Gets sections were correct because totals_cmd::m_latency is double; only
the outer totals::m_latency was unsigned long long, and run_stats::summarize
assigned the averaged double into it, truncating fractional milliseconds.

Three changes:

- run_stats_types.h: change totals::m_latency from unsigned long long to
  double so the averaged value survives summarize().

- run_stats_types.cpp: fix a long-standing typo in totals::add() that
  conflated m_latency and m_total_latency. The two fields held the same
  value before summarize() ran, so the typo was harmless on the live
  accumulator path but corrupted m_total_latency once summarize() turned
  m_latency into an average for the multi-run aggregate path.

- run_stats.cpp: have summarize() also write the raw latency sum into
  result.m_total_latency, so the BEST/WORST/AGGREGATED sections produced
  by aggregate_average() carry a correct "Accumulated Latency".

Tests: tests/test_json_output_integrity.py asserts the invariant
Latency == Average Latency == Accumulated / Count for Sets, Gets, Totals
across single-run, SET-only, GET-only and multi-run aggregated outputs,
plus the per-second time-series buckets. The existing total_latency > 0
check was insufficient because the bug surfaced as 1.000 ms (looks
plausible) rather than 0.

Refs: RED-191460

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

2 participants