Skip to content

Fix BEST/WORST RUN RESULTS always showing run #1 with --run-count - #571

Merged
fcostaoliveira merged 1 commit into
masterfrom
fix/run-count-best-worst
Oct 13, 2026
Merged

fcostaoliveira merged 1 commit into
masterfrom
fix/run-count-best-worst

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With --run-count N, BEST RUN RESULTS and WORST RUN RESULTS always show run #1, even when the runs differ clearly:

$ memtier_benchmark -p 16565 -t1 -c2 --test-time 1 --run-count 3 --print-all-runs --hide-histogram
RUN #1 RESULTS     Totals 58495.78
RUN #2 RESULTS     Totals 29826.29
RUN #3 RESULTS     Totals 62330.32
BEST RUN RESULTS   Totals 58495.78   <- run 1, expected run 3
WORST RUN RESULTS  Totals 58495.78   <- run 1, expected run 2

Root cause

The per-run run_stats objects returned by run_benchmark() are built by client_group::merge_run_stats() via run_stats::merge(). merge() averages m_start_time/m_end_time but never sets m_started. Since #350 (0228bac), get_duration_usec() returns 0 while m_started is unset. The selection loop's divisor therefore fell back to 1, and (int)(ops * 1000000) overflowed to the same value for every run, so run #1 won both comparisons. m_totals.m_ops was correct all along; the printed Ops/sec column was right because summarize() uses ts_diff(m_start_time, m_end_time) directly.

Fix

  • run_stats::merge(): set m_started once a started run is merged in (merge_run_stats() only merges started clients), so get_duration_usec() works on merged stats.
  • The best/worst loop compares a double ops/sec rather than an (int)-cast value, and uses 0 for a zero-duration run instead of dividing by 1.

Test

Added test_run_count_best_worst_selection to tests/test_cli_validation_run_count.py. It runs --run-count=3 --print-all-runs and checks that BEST's Totals.Ops/sec equals the maximum per-run value and WORST's equals the minimum.

  • Without the fix (origin/master 667f187): FAIL 3/3 runs, e.g. 53037.03 == 86452.84 and 53037.03 == 21262.8 for per-run Ops/sec [53037.03, 86452.84, 21262.8].
  • With the fix: PASS 6/6 runs. The rest of the file still passes.

The test can only pass on unfixed code if run #1 is both the fastest and the slowest run, which means all three runs would have to report identical Ops/sec.

Fixes #565

Affected versions: 2.3.0 through 2.5.2 and master. Introduced by 0228bac ("Add client staircase ramp-up for incremental connection growth", #350).

🤖 Generated with Claude Code


Note

Low Risk
Localized fix to multi-run reporting and stats merge; no auth or data-path changes, with a targeted regression test.

Overview
Fixes BEST/WORST RUN RESULTS always picking run #1 when using --run-count.

Merged per-run stats now set m_started in run_stats::merge() so get_duration_usec() returns a real duration instead of 0 (which made every run look equally fast/slow). The best/worst selection loop now compares double Ops/sec and treats zero duration as 0 ops/sec instead of dividing by 1 and overflowing an int cast.

Adds test_run_count_best_worst_selection to assert BEST/WORST Totals.Ops/sec match the max/min across RUN #N RESULTS for --run-count=3 --print-all-runs.

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

The per-run run_stats are built with merge(), which never set m_started.
Since 0228bac (#350), get_duration_usec() returns 0 until m_started is
set, so every run's duration was 0, the ops/sec divisor fell back to 1
and the (int) cast overflowed to the same value for every run. Run #1
then won both the best and the worst comparison.

Set m_started in merge() when a started run is merged in, and compare
runs by a double ops/sec instead of an int-cast value.

Fixes #565

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira merged commit 5a304b0 into master Oct 13, 2026
121 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: BEST and WORST RUN RESULTS always show the same run

1 participant