Repository navigation
Average merged Start/Finish time over all threads' clients - #723
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. Passing the counter in from the caller is the smallest fix and keeps #707's rule. I checked the new One question, not blocking: each merge still floors to a whole microsecond. That error adds up roughly linearly with client count, which is where the 935 us at 6000 clients comes from, so very large runs would drift Start/Finish by several ms. The old formula floored the same way, and duration mostly cancels out, so this isn't a regression. Did you consider summing On the output change: Ops/sec and KB/sec can shift for multi-thread runs, but the old numbers were wrong, so I don't see a less-breaking design that would be worth keeping. The release note covers it. Looks good to me otherwise. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 43979dc. Configure here.
With more than one thread, run_benchmark() calls merge_run_stats() once per thread, all into the same run_stats. merge_run_stats() started its averaging weight at 1 on every call, and run_stats::merge() computes the running mean as (avg * (w - 1) + new) / w, so the first client of each thread replaced the average built so far. The merged Start time, Finish time and Total duration, and every Ops/sec and KB/sec derived from them, came only from the last thread's clients. Let the caller own the counter: run_benchmark() passes the same one to every thread's merge_run_stats(), so the weight keeps growing across threads. Clients that never started still do not advance it (#707). The test runs four rate-limited single-client threads and disconnects one client once, so it ends about 1 s after the others. The merged duration must be the mean of the four (about 3.25 s), not the last thread's 3 s or 4 s. Fixes #709 Co-Authored-By: Claude Opus 5.5 <[email protected]>
timeval_factorial_average() computed (a * (w - 1) + b) / w in int64 microseconds. With epoch timestamps (~1.8e15 us) a * (w - 1) wraps once w passes about 5100. The weight used to restart for every thread, so this needed one thread with over 5100 clients; now that it counts all the run's clients, -t 6 -c 1000 already gave negative Start and Finish times in the JSON. Compute a + floor((b - a) / w) instead. It gives the same value as the old formula wherever that did not overflow, so small runs are unchanged. run_stats_merge_test merges 6000 runs with realistic timestamps through run_stats::merge() and checks the merged start and duration, plus exact results for small weights. The RLTest assertions now report the exit code, the CLIENT KILL result and the stderr tail. Refs #709 Co-Authored-By: Claude Opus 5.5 <[email protected]>
43979dc to
49f2259
Compare
CLIENT KILL can reach the client as EOF, which logs "Connection dropped", or as an error (ECONNRESET, or a TLS error), which logs "Connection error". Both paths reconnect and log "attempting reconnection", so match that. Note why the rate limiter does not catch up after the reconnect, and give the unit test's deterministic 935 us drift a 2 ms bound. Refs #709 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the review. Answers, as of f2ece53: RLTest flakiness. I checked the failures I saw locally:
On the bounds:
Rate limiter catch-up. It does not catch up. Release notes. Added to the PR body, including the separate Cross-thread coverage. You're right that |
With the default 1 s reconnect delay the correct mean (~3.24 s) sat only ~0.25 s above the buggy last-thread value (~3.0 s). One slow client could carry master over the 3.1 s lower bound, and a weight that overcounts the first client (~3.44 s) passed the 3.65 s upper bound. Use --reconnect-backoff-factor=3 so the killed client waits 3 s. The mean is then ~3.75 s, and the bounds are that mean plus or minus half of the delayed client's share (3375-4125 ms). Master gives ~3.0 s and a weight advancing by 2 per client gives ~4.36 s. Correct the docstring: the killed client connects first, so it is never in the last thread, and master always reports ~3 s. Refs #709 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. On the floor drift: yes, I considered keeping an int64 sum of |

Problem
With more than one thread (
-t N), the JSONRuntimeStart time,Finish timeandTotal durationare meant to be the mean over all clients. They were the mean over the last thread's clients only. Every Ops/sec and KB/sec in the report is divided by that duration, so when the threads' durations differ (per-thread throughput under--requests, a slow or reconnecting connection, a thread cut short), every rate is computed against the wrong window.Root cause
run_benchmark()callsclient_group::merge_run_stats()once per thread, and every call merges into the samerun_stats.merge_run_stats()setiteration_counter = 1at the start of every call.run_stats::merge()computes the running meantimeval_factorial_average(avg, new, w) = (avg*(w-1) + new)/w, so each thread's first client, merged with weight 1, replaced the average built so far.Fix
The caller owns the counter.
merge_run_stats(run_stats *target, unsigned int &iteration_counter)takes it by reference, andrun_benchmark()passes the same one (starting at 1) for every thread, so the weight keeps growing across threads. #707's rule is kept: clients that never started are still merged for their connection errors and do not advance the counter. This is the only caller.Overflow in the running mean
With the weight now counting all of the run's clients,
timeval_factorial_average()overflowed: it computed(a*(w-1) + b)/win int64 epoch microseconds (~1.8e15), which wraps oncewpasses about 5100. Before this PR the weight restarted per thread, so that took more than about 5100 clients in one thread (-t 1 -c 5200already broke on master). The mean is now computed asa + floor((b - a)/w). It gives the same value as the old formula wherever the old one did not overflow, so small runs are unchanged.Test evidence
New RLTest
test_reconnections.py::test_merged_duration_averages_all_threads(standalone, skipped on cluster). It runs-t 4 -c 1 --requests=300 --rate-limiting=100 --reconnect-on-error --reconnect-backoff-factor=3, so each client takes about 3 s. One client is killed once withCLIENT KILL ID, waits 3 s before reconnecting, and so ends about 3 s after the others. The rate limiter resets its budget on disconnect and does not catch up. The correct mean is about 3.75 s. The killed client connects first, so it is never in the last thread, and master always reports the last thread's about 3 s. The test asserts the mean plus or minus half of the delayed client's share:3375 < Total duration < 4125ms.Local runs at 5886d22 against redis on localhost:
The margins are about 380 ms below the branch value, 360 ms above master, and 230 ms below the mutant. An earlier version of the test used the default 1 s delay and a 3100-3650 ms window. It was too narrow: master once passed at 3110 ms, and the counter mutant (~3442 ms) passed too.
The test matches the "attempting reconnection" log line. Both disconnect paths write it: EOF ("Connection dropped") and error ("Connection error", e.g. ECONNRESET or TLS). Requiring "Connection dropped" was a likely cause of a rare earlier failure (Bugbot). The assertions also report the exit code, the
CLIENT KILLresult, whether memtier was still running at the kill, and the stderr tail. Two earlier local failures were host stalls: RLTest reported Total durations of 2759094 ms and 6351734 ms, and its own "Test Took" time and/proc/uptimeshowed the same stall.Unit test
run_stats_merge_test(newmake checkprogram, linked likecluster_hslot_test). It merges 6000 runs with realistic epoch timestamps throughrun_stats::merge()and checks the merged start (within 2 ms of the exact mean; flooring each merge drifts it by a fixed 935 us with these inputs) and the duration (exact). It also checks exact floor results for small weights.-1282306700097482, duration3074466889699128us.End-to-end against redis with
maxclients 20000,--hide-histogram --json-out-file:-t 6 -c 1000 --requests 200-t 16 -c 900 --requests 100The RLTest now matches the "attempting reconnection" log line, which both the EOF ("Connection dropped") and the error ("Connection error") disconnect paths write; requiring "Connection dropped" was one cause of the rare failures (Bugbot). After this change it passed 15/15 locally. The assertions also report the exit code, the
CLIENT KILLresult, whether memtier was still running at the kill, and the stderr tail. In later local batches every failure on this branch was a host stall: one run reported Total duration 2759094 ms and another 6351734 ms, and RLTest's own "Test Took" time and/proc/uptimeshowed the same stall. One failure had memtier still running at the kill with rc=0 and killed=1, but its stderr tail was not saved, so its cause is unconfirmed.Release notes
RuntimeStart time, Finish time and Total duration are now the mean over all clients, not over the last thread's clients only (Multi-thread runs: merged Start time / Finish time / Total duration average only the last thread's clients (merge_run_stats restarts the averaging weight per thread) #709). Multi-thread Ops/sec and KB/sec can shift compared with 1.2.4-2.5.2 when threads ran for different lengths of time.-t 1 -c 5200.--hdr-file-prefix.hgrmlog: the#[StartTime: ...]header and the interval timestamps written bysave_hdr_log_format. These also change for multi-thread runs, and above about 5100 clients they were corrupt in the same way.Affected versions
1.2.4 through 2.5.2 (latest) and master.
iteration_counterwhilerun_benchmark()already calledmerge_run_stats()once per thread. The first tag that contains it is 1.2.4.merge_run_stats(),run_stats::merge()and the per-thread merge loop are unchanged in substance.Fixes #709
🤖 Generated with Claude Code
Note
Medium Risk
Changes core benchmark reporting math (merged duration and all derived rates) for multi-thread runs; behavior is intentional but affects published JSON metrics.
Overview
Fixes #709: with
-t> 1, JSON RuntimeStart time,Finish time, andTotal duration(and every rate derived from them) were averaged over the last thread’s clients only, because eachclient_group::merge_run_stats()call reset the merge weight to 1.run_benchmark()now keeps a singlemerge_iterationcounter (starting at 1) and passes it by reference into every thread’smerge_run_stats(), so the running mean spans all clients across threads. Clients that never started still do not advance the counter.timeval_factorial_average()inrun_stats.cppusesa + floor((b - a) / weight)instead of(a * (weight - 1) + b) / weight, avoiding int64 overflow when thousands of clients are merged with epoch microsecond timestamps.Adds
run_stats_merge_test(make check) and RLTesttest_merged_duration_averages_all_threads(4 threads, one delayed reconnect) to lock in the correct mean duration.Reviewed by Cursor Bugbot for commit f2ece53. Bugbot is set up for automated code reviews on this repo. Configure here.