Skip to content

Fix doubled Totals KB/sec with arbitrary commands - #573

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/arbitrary-totals-kbps
Oct 13, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/arbitrary-totals-kbps

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

In arbitrary-command mode (--command=...), the Totals row's KB/sec is about twice the sum of the per-command rows. For example, with --command "SET __key__ __data__" --command "GET __key__" --run-count 2, the rows are 3009.17 + 1520.75 KB/sec but Totals shows 9059.85. The Totals KB/sec RX / KB/sec TX split is also wrong: both directions are set to the same, inflated value. This affects the text table, the JSON, and the CSV output, for single runs and for the --run-count BEST/WORST/AGGREGATED sections.

Root cause

run_stats::summarize() adds m_ar_commands.bytes() to both result.m_bytes_rx and result.m_bytes_tx. But ar_one_sec_cmd_stats::bytes() already returns rx + tx for every command. Totals KB/sec is computed from rx + tx, so the arbitrary-command bytes are counted twice. SET and GET are not affected, because they already add rx and tx separately. The bug came in with 20c013d (#246), which split m_bytes into _rx and _tx.

Fix

Replace ar_one_sec_cmd_stats::bytes() with bytes_rx() and bytes_tx(). bytes() has no other caller. Each Totals direction now sums only its own bytes, the same way the SET/GET terms do.

Test

The new test test_json_output_integrity.py:test_json_arbitrary_commands_totals_bandwidth runs SET + GET --commands with --run-count=2. It asserts that Totals KB/sec, KB/sec RX and KB/sec TX equal the sum of the per-command rows (within %.2f rounding) in BEST and WORST. In AGGREGATED it checks only KB/sec, because the aggregated Totals RX/TX are a separate pre-existing problem (see below).

  • Before (origin/master): the test fails. BEST RUN RESULTS: Totals 'KB/sec' (41053.59) != sum of ['Sets', 'Gets'] (20526.79), RX 20526.79 vs 15670.36, TX 20526.79 vs 4856.45. WORST shows the same, and AGGREGATED shows 36322.09 vs 18161.05.
  • After: the test passes, and so does all of test_json_output_integrity.py (10/10).

Note: separate pre-existing issue, not fixed here

In the --run-count AGGREGATED AVERAGE section, Totals KB/sec RX and KB/sec TX are always 0.0. totals::add() does not accumulate m_bytes_sec_rx/_tx, and run_stats::aggregate_average() does not average them. This happens for all workloads, not only --command. I left it out of this PR to keep the diff small.

Fixes #566

Affected versions: 2.1.0 through 2.5.2, and master. Introduced by 20c013d (#246).

🤖 Generated with Claude Code


Note

Low Risk
Narrow stats aggregation fix for arbitrary-command mode with a targeted regression test; no auth, I/O protocol, or runtime behavior changes beyond reported bandwidth totals.

Overview
Fixes #566: in --command mode, Totals bandwidth in JSON/text/CSV was roughly double the sum of per-command rows because arbitrary-command bytes were counted twice in RX and TX.

ar_one_sec_cmd_stats no longer exposes a single bytes() that summed RX+TX for every command. It now has bytes_rx() and bytes_tx(), and run_stats::summarize() adds those separately into result.m_bytes_rx / result.m_bytes_tx—matching how SET/GET totals are built.

A regression test in test_json_output_integrity.py runs SET+GET arbitrary commands with --run-count=2 and checks that Totals KB/sec (and RX/TX in BEST/WORST) equals the sum of per-command rows within rounding slack.

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

run_stats::summarize() added ar_one_sec_cmd_stats::bytes(), which is
already rx + tx, to both the Totals RX and TX byte counters. In --command
mode the Totals KB/sec was therefore twice the sum of the per-command
rows, and the Totals RX/TX split was wrong in the text, JSON and CSV
outputs (including the --run-count BEST/WORST/AGGREGATED sections).

Split bytes() into bytes_rx() and bytes_tx() so each direction only
counts its own bytes, like SET/GET already do.

Introduced in 20c013d (#246).

Fixes #566

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

Copy link
Copy Markdown
Collaborator Author

Split out as a follow-up: #577. With --run-count, the AGGREGATED AVERAGE Totals KB/sec RX/KB/sec TX are always 0.0 in the JSON, because totals::add() and run_stats::aggregate_average() skip those fields. It has been there since 2.1.0 (#246), and this PR doesn't change it.

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.

Arbitrary-command mode: Totals KB/sec is double-counted

1 participant