Skip to content

Fix AGGREGATED Totals KB/sec RX/TX always 0.0 in JSON with --run-count (#577) - #581

Merged
fcostaoliveira merged 2 commits into
masterfrom
fix/aggregated-totals-rx-tx
Oct 13, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
fix/aggregated-totals-rx-tx

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --run-count > 1, the AGGREGATED AVERAGE RESULTS → Totals section of the JSON output always reports "KB/sec RX": 0.0 and "KB/sec TX": 0.0, for every workload (default SET/GET and --command mode). The combined KB/sec, the per-command rows and the BEST/WORST sections are correct. The text table only prints the combined KB/sec, so only the JSON is wrong.

"Connection Errors/sec" in the same section has a related bug. It reports the sum of the per-run rates rather than their mean. One reviewer measured BEST 1.86, WORST 1.9 and AGGREGATED 3.76 with --reconnect-on-error while connections were being killed.

Root cause

20c013d (#246) added m_bytes_sec_rx / m_bytes_sec_tx to both totals_cmd and totals. It wired them into totals_cmd::add() / aggregate_average(), but not into the run-level totals:

  • The totals::totals() constructor never initializes the two fields.
  • totals::add() adds m_bytes_sec but not the RX/TX fields.
  • run_stats::aggregate_average() divides m_bytes_sec by the run count but not the RX/TX fields.

print() calls summarize() only when m_stats is non-empty. The AVERAGE object has no per-second stats, so that call is skipped and nothing overwrites the value. In practice it came out as 0.0, but strictly it was indeterminate.

m_connection_errors_sec is in the same position: totals::add() sums it, but run_stats::aggregate_average() never divides it.

Fix

  • Initialize, accumulate and average m_bytes_sec_rx / m_bytes_sec_tx exactly like m_bytes_sec, as totals_cmd already does.
  • Divide m_totals.m_connection_errors_sec by the run count alongside them.

That adds 7 lines in run_stats_types.cpp and run_stats.cpp.

I audited the other fields as well:

  • totals_cmd (Sets/Gets/Waits/arbitrary commands, via ar_totals_cmd) already initializes, adds and averages both RX/TX rates.
  • The raw m_bytes_rx / m_bytes_tx and m_connection_errors counters are summed across runs on purpose. They are cumulative, like Count.
  • run_stats::summarize(), the BEST/WORST/single-run path, computes the rates directly from the per-second stats.

The only gaps in the run-level totals were the three RX/TX ones above and m_connection_errors_sec.

Tests

All tests are in tests/test_json_output_integrity.py.

test_json_aggregated_totals_rx_tx (new) runs --run-count=3 --print-all-runs on 2 threads. The run count, the thread count and the literal 2 all differ, so a wrong divisor can't pass. It checks these AGGREGATED Totals values:

  • RX and TX are > 0.
  • RX and TX equal the sum of the per-command rows.
  • RX + TX ≈ KB/sec.
  • KB/sec, RX and TX each equal the mean of the RUN #i RESULTS sections.
  • Connection Errors/sec is 0 when no connection breaks.

test_json_aggregated_connection_errors_sec (new) runs 3 × 2 s with --reconnect-on-error while a thread runs CLIENT KILL TYPE normal SKIPME yes every 0.25 s. It asserts that connection errors happened, and that the AGGREGATED Connection Errors/sec equals the mean of the per-run values.

test_json_arbitrary_commands_totals_bandwidth (#566) now checks RX/TX in the AGGREGATED section too, using the same per-run mean check. Before this fix it had to skip them.

Before:

  • On origin/master c9a65a0, the RX/TX tests fail, for example:
    AGGREGATED AVERAGE RESULTS (2 runs): Totals RX (0.0) + TX (0.0) != KB/sec (7458.56)
    
  • On this PR's first commit (0c52c25, RX/TX fixed only), the connection-errors test fails:
    Totals 'Connection Errors/sec' (10.53) != mean of the per-run values [3.19, 3.79, 3.56] (3.5133)
    
  • With a mutant that divides RX/TX by a literal 2, the 3-run test fails:
    Totals 'KB/sec RX' (57.71) != mean of the per-run values [37.37, 52.88, 25.17] (38.4733)
    

After: test_json_output_integrity.py passes 12/12, three times in a row.

Manual repro (-t 1 -c 2 -n 5000 --run-count 3, local redis), Totals KB/sec / RX / TX:

master this PR
BEST 5186.01 / 596.96 / 4589.05 4819.02 / 554.71 / 4264.31
WORST 3402.63 / 391.67 / 3010.96 4107.42 / 472.80 / 3634.62
AGGREGATED AVERAGE 4436.79 / 0.0 / 0.0 4526.30 / 521.02 / 4005.29

Release notes

With --run-count > 1, the JSON AGGREGATED AVERAGE RESULTS → Totals section changes in two ways:

  • KB/sec RX / KB/sec TX now report the per-run average. Before, they were always 0.0.
  • Connection Errors/sec is now the mean of the per-run rates. Before, it was their sum, so older JSON overstates it by a factor of the run count. The Connection Errors count is still the total across runs, unchanged.

Fixes #577

Affected versions

2.1.0–2.5.2 and master (introduced by 20c013d / #246).

🤖 Generated with Claude Code

fcostaoliveira and others added 2 commits October 13, 2026 20:28
With --run-count > 1 the AGGREGATED AVERAGE Totals "KB/sec RX" and
"KB/sec TX" JSON fields were always 0.0. totals::add() did not
accumulate m_bytes_sec_rx/m_bytes_sec_tx, run_stats::aggregate_average()
did not divide them by the run count, and the totals constructor left
them uninitialized (so the printed value was strictly indeterminate).

Initialize, accumulate and average them like m_bytes_sec, matching what
totals_cmd already does for the per-command rows.

Extend test_json_output_integrity.py: the AGGREGATED Totals RX/TX must
equal the sum of the per-command rows, add up to KB/sec, and equal the
mean of the two runs with --run-count=2.

Fixes #577

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Widen the #577 fix to the same bug class: totals::add() sums
m_connection_errors_sec across runs, but run_stats::aggregate_average()
never divided it, so the AGGREGATED "Connection Errors/sec" was the sum
of the per-run rates instead of their mean. Divide it alongside the
RX/TX rates.

Make the tests discriminate the run-count divisor:
- test_json_aggregated_totals_rx_tx now uses --run-count=3 on 2 threads
  with --print-all-runs, and checks each AGGREGATED Totals rate against
  the mean of the RUN #i sections instead of BEST/WORST. A divisor of a
  literal 2 or of the thread count no longer passes. It also asserts
  Connection Errors/sec stays 0 when no connection breaks.
- test_json_arbitrary_commands_totals_bandwidth uses the same per-run
  mean check.
- New test_json_aggregated_connection_errors_sec kills memtier's
  connections every 0.25s during 3 x 2s runs (--reconnect-on-error) and
  checks the AGGREGATED Connection Errors/sec is the per-run mean.

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

Copy link
Copy Markdown

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

Thanks for this. The C++ change looks right to me. totals now initializes, adds and averages m_bytes_sec_rx/m_bytes_sec_tx the same way totals_cmd already does in run_stats_types.cpp. Dividing m_connection_errors_sec in aggregate_average() is a good catch too: totals::add() was already summing it, so the AGGREGATED value really was a sum of per-run rates. The tests fail on master and pass with the fix, and using 3 runs on 2 threads so the divisor can't be confused with the thread count is a nice touch. That meets the same bar as the existing integrity tests from #364.

One question about test_json_aggregated_connection_errors_sec. It kills connections every 0.25s over 2s runs and then asserts that memtier exits zero. I think that's fine with --reconnect-on-error --max-reconnect-attempts=0 (0 means unlimited in shard_connection.cpp). But I wonder if it can flake on a slow CI runner, or in the cluster/TLS cells, when a kill lands during connection setup or the slot-map fetch. Did you run it a few times across the CI matrix? If it turns out to be noisy, one option is to drop the exit-code assertion and keep only the per-run-mean check.

Nitpicking: Connection Errors/sec is a user-visible change in the AGGREGATED output (sum → mean). It's clearly a fix, but it may be worth a line in the release notes for anyone comparing old JSON.

Otherwise this looks good to me.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Answers to both points:

1. Can test_json_aggregated_connection_errors_sec flake? I measured it and found no flakes, so I kept the exit-code assertion.

  • CI on 7566668: the test ran in 17 cells and passed in every one. Each pass includes the errors > 0 assertion, so every cell really saw killed connections. The cells:
    • Standalone/OSS: Single Endpoint (Plaintext and TLS) and OSS TLS v1.2/v1.3.
    • Cluster: OSS-CLUSTER API, Plaintext and TLS.
    • Sanitizers: ASAN, TSAN and UBSan in the TLS-cluster, TLS-standalone and OSS TLS v1.3 (misc) cells, plus UBSan in the plaintext cluster and standalone cells.
  • Local runs, 33 in total, all passed:
    • standalone: 10/10
    • standalone with all 14 cores busy: 8/8
    • --env oss-cluster --shards-count 3: 5/5
    • TLS standalone: 5/5
    • TLS oss-cluster: 5/5

Why a kill during connection setup or the slot-map fetch shouldn't fail the run: with --reconnect-on-error --max-reconnect-attempts=0 (unlimited), a connection that breaks at any stage goes through the normal reconnect path. Each run is bounded by --test-time=2, not a request count, so lost requests can't leave a run unfinished either. I kept the exit-code check for a reason. If memtier aborted, the RUN #i sections would be missing and the mean check would fail anyway. Keeping the check makes that failure obvious instead of confusing. If it ever does flake in CI, dropping the check or skipping the test on cluster is a one-line change.

2. Release notes: I added a "Release notes" section to the PR description. It says that the AGGREGATED Connection Errors/sec is now the mean of the per-run rates instead of their sum, so old JSON overstated it by a factor of the run count. It also notes that RX/TX are no longer stuck at 0.0, and that the Connection Errors count is still the total across runs.

🤖 Generated with Claude Code

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 Totals KB/sec RX and KB/sec TX are always 0.0

1 participant