Skip to content

Tighten realtime-latency sample thresholds and window tests - #824

Merged
fcostaoliveira merged 2 commits into
masterfrom
claude/pr386-followups-20261024
Oct 24, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
claude/pr386-followups-20261024

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #386 with the review points left for after the merge.

Problem

  • percentile_min_samples() snapped every value to at most 7 significant digits. That made all-nines percentiles exact, but other percentiles came out slightly off: p99.99991 gave 1111111 instead of 1111112, p99.99999993 came out 28571 too high, and p99.9999999999 gave 999999999999 instead of 1e12.
  • The run warning said "at most about N" even for --requests, where N is exact.
  • No test caught a cluster run that also applied the pre-run check. That check ignores the endpoint fan-out, so it adds a second, wrong window warning.
  • test_latency_window_ring_smooths_spikes didn't test smoothing. The README example's spacing didn't match the real output, and one help string was split in an odd place.

Fix

  • 100/(100-p) snaps to the intended value only when it lies within the error from parsing p as a double: at most half an ulp of 100, amplified by 100/(100-p). Otherwise it rounds up. The rounding uses an integer power of ten, so it is exact.
  • The --requests bound drops "about"; the approximate rate-limit bound keeps it.
  • A comment now says the cluster bound comes from the first topology only. A later, larger topology can exceed it; that is tracked separately.
  • The window-warning test asserts that exactly one warning: p99.9 needs line is printed.
  • The window-row test is renamed to test_latency_window_row_reports_values. The README example now matches the real column layout, and the help string is rejoined.

Tests

  • Minimum sample counts, built binary against exact rational arithmetic: p99.9 → 1000, p99.97 → 3334, p99.99991 → 1111112, p99.9999 → 1e6, p99.999999 → 1e8, p99.99999999 → 1e10, p99.9999999999 → 1e12, p99.123 → 115, p66.6667 → 4, p50 → 2. p99.99999993 gives 1428571456 against an exact 1428571429; that is within double precision, and the error is on the safe side, so p is marked unresolved slightly early rather than missed.
  • make check: 18/18. make format-check is clean.
  • test_realtime_latencies.py 8/8 and test_progress_interval.py 6/6, standalone. memtier authenticated against a password-protected server, with no NOAUTH replies.
  • In a 3-shard cluster, the new assertion passes on this branch. It fails on a mutant that runs the pre-run check in cluster mode too: that mutant prints both the 202 and the 606 window bound.

Affected versions

Only #386 code, merged as 9bf3960. No release tag contains it.

🤖 Generated with Claude Code


Note

Low Risk
Changes only benchmark reporting thresholds, stderr warnings, and tests for --realtime-latencies; no runtime request path or server interaction.

Overview
Tightens how --realtime-latencies decides when a percentile is “resolved” and aligns warnings/output with that logic.

percentile_min_samples() no longer snaps every value to seven significant digits. It now treats ceil(100/(100-p)) as the intended threshold when double parsing error allows (e.g. p99.9999 → 1e6, p99.9999999999 → 1e12), and rounds up otherwise (e.g. p99.99991 → 1111112). Pre-run warnings and live * marking still use this helper; run-bound messages drop “about” for exact --requests caps, print percentiles with %.15g, and document that cluster rate-limit bounds come from the first topology only.

Docs/help get minor fixes (README example column spacing, --realtime-latencies help wrap). Tests add test_percentile_sample_thresholds, simplify the latency-window row test, match exact --requests warning text, and assert only one p99.9 window warning in cluster runs.

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

percentile_min_samples now snaps 100/(100-p) only when it lies within
the parsing error of p of the value the user meant, and otherwise
rounds up, so p99.99991 needs 1111112 samples and p99.9999999999 needs
1e12. The run warning no longer says "about" for the exact --requests
bound. Document that the cluster bound comes from the first topology.

Assert that a rate-limited window run prints exactly one percentile
warning, which catches a cluster run that also applies the pre-run
check without the endpoint fan-out. Rename the window-row test to what
it checks, and fix the README example spacing and line wrap and a split
help string.

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 following up on #386. I went through it and only have two small comments.

I worked through the new percentile_min_samples() for p99.9999, p99.99991, p99.9999999999 and p99.99999993, and I think it does what the description says. The error bound is 2x the half-ulp-of-100 the comment mentions, which seems like a sensible margin. The largest possible n (100 minus one ulp below 100) is around 7e15, so llround stays well within range.

  1. The rounding change is the main fix here, but I don't see a committed test that pins the new values. The description checks them against exact rational arithmetic by hand, but nothing in tests/ would fail if the old 7-digit snapping came back. test_latency_window_counts_every_sample_and_marks_unresolved already asserts the exact --requests warning text for p99.99. Would it be cheap to add one or two more there, e.g. --print-percentiles=99.99991 should warn "needs at least 1111112"? That case gave 1111111 on master, so the test would fail before this PR and pass with it, the same way Fix JSON Totals latency precision and add integrity regression tests #364 did.

  2. Nitpicking: the help string was rejoined, but clang-format now leaves "(1M " on a line of its own, which is just a different odd split. It doesn't affect the output, so skip it if it's a fight with the formatter.

The new single-warning assertion in the rate-limit test is a nice catch, especially since you checked that it fails on the cluster mutant. The fix looks right to me; I'd just like the rounding behavior pinned by a test before this merges.

(would file this as a comment, not a formal block)

Add test_percentile_sample_thresholds, which checks the warning for
p99.9, p99.97, p99.9999, p99.99991 and 12 nines against the exact
ceil(100 / (100 - p)); the old 7-digit snapping fails it (1111111 for
p99.99991). The Python helper now computes the threshold exactly from
the printed percentile.

Print percentiles in the realtime rows and warnings with %.15g, so 12
nines no longer display as p100. Rejoin the help string, note that the
error bound is doubled for margin, and make the window-row test's
docstring match what it asserts.

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

Copy link
Copy Markdown
Collaborator Author

Thanks. Both points are addressed in dad8544:

  1. New test_percentile_sample_thresholds: a one-request run with --print-percentiles=99.9,99.97,99.9999,99.99991,99.9999999999, asserting each warning's threshold against exact ceil(100/(100-p)) (1000, 3334, 1e6, 1111112, 1e12). Restoring master's percentile_min_samples() fails it (1111111 for p99.99991). This also showed the realtime labels printed 12 nines as p100; the rows and warnings now use %.15g. The final table and JSON keys keep their existing labels.
  2. The help string is rejoined without the stray "(1M " line; the rendered --help is unchanged.

make check passes 18/18. test_realtime_latencies.py passes 9/9 standalone and 9/9 on a 3-shard cluster, with memtier authenticated.

@fcostaoliveira
fcostaoliveira merged commit 4885668 into master Oct 24, 2026
150 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.

1 participant