Broker startup pre-connect: adaptive straggler-grace window - #19519
Open
jineshparakh wants to merge 2 commits into
Open
Broker startup pre-connect: adaptive straggler-grace window#19519jineshparakh wants to merge 2 commits into
jineshparakh wants to merge 2 commits into
Conversation
Signed-off-by: Jinesh Parakh <jineshparakh@hotmail.com>
yashmayya
reviewed
Sep 9, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19519 +/- ##
============================================
- Coverage 67.74% 67.70% -0.05%
- Complexity 1424 1430 +6
============================================
Files 3489 3490 +1
Lines 224672 224943 +271
Branches 35468 35516 +48
============================================
+ Hits 152210 152292 +82
- Misses 60445 60616 +171
- Partials 12017 12035 +18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: Jinesh Parakh <jineshparakh@hotmail.com>
Collaborator
Author
|
@yashmayya can you please re-review? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR flow
Adaptive straggler-grace window scales wait time after first connect to twice its latency, preventing premature timeout when channels complete in waves.
AI-generated · Green: added · Yellow: modified · Red: removed · Gray: existing
Diff evidence
Broker startup pre-connect: adaptive straggler-grace window
Summary
Follow-up to #19407 (broker startup pre-connect for broker-to-server channels). That PR releases startup
early once channels stop arriving for a fixed
STRAGGLER_GRACE_MS(2 s) quiet window, so one stuck servercannot hold the readiness gate for the whole budget. This change makes that window adaptive and bounded:
2 s becomes a floor, the window scales to twice the first observed connect latency, and a new
STRAGGLER_GRACE_CAP_MS(10 s) ceiling keeps it from growing without limit.worker threads — from being misread as a straggler and abandoning healthy channels that are only queued.
connect would stretch the window so far that a genuinely dead server would hold the gate for most of the
budget.
No config, wire, or API changes.
Problem
Pre-connect submits every
(server, tableType)connect to a pool capped atMAX_CONNECT_THREADS = 16and counts completions off an
ExecutorCompletionService. Once the first channel is up, each subsequentpollwaits at most the grace window; a quiet window that long is taken as "what's left is stuck", andstartup is released.
A single fixed value cannot satisfy both goals at once:
completes in waves ~one connect-latency apart. If a connect takes ~3 s, the gap between waves exceeds a
2 s window, so after the first ~16 the next
polltimes out during the quiet gap and startup releases,counting only the first wave (~16/48) even though all 48 were healthy.
whole window on every startup.
Fix
The window is
max(STRAGGLER_GRACE_MS, min(STRAGGLER_GRACE_CAP_MS, 2 * firstConnectLatency)), extracted asServerPreConnector.stragglerGraceMs(...):2 * Lstays under the floor when
Lis small, e.g. a ~120 ms TLS connect).2 * L): since all tasks start together, the first success approximates one connect's latencyL, and the waves are ~Lapart, so a2Lwindow waits through each wave instead of abandoning it.slow the healthy connects are. 10 s (5x the floor) covers realistic healthy connect latencies while
keeping the dead-server delay well under the budget.
Unchanged: until the first successful connect the whole budget is available (nothing up yet, so "every
server slow" and "a few stuck" are indistinguishable, and a fast failure must not start the clock). The
readiness gate, the pool cap, the per-connect deadline-derived timeout, and the graceful (not
shutdownNow) executor teardown are all untouched.Known limitation: mixed connect latencies
The window is sized off the first (fastest) connect. When one server is fast but the rest are slower
than the floor, the fast connect pins the window at the 2 s floor, and the slower-but-healthy channels
arrive after it has elapsed — so they are released before being counted (e.g. a cluster with one ~10 ms
server and the rest at ~6 s counts 1). No window value fixes this: a reactive release decision
necessarily fires before the slow channels return, and inflating the window to cover them would impose that
cost on every cluster (including fast ones) — trading the straggler protection back away.
This case is benign: the uncounted channels still finish on their daemon threads (
shutdown(), notshutdownNow()) and are still published for the first query to reuse. Only the returned count and thestartup log under-report; correctness and the lazy-connect fallback are unaffected. It is documented and
tested (
mixedLatencyUnderCountsAndIsNotFixedByTheCeiling) so a later change does not "fix" it by inflatingthe window for everyone.
What this does not change
16-worker pool cap stays — it is a throughput cap; this change removes the wave under-count withouttouching it.
pre-connect exists to warm.
2 * Lis below the 2 s floor, the floor is used, so thewindow is identical to Add broker startup pre-connect for broker-to-server channels (SSE) #19407.
min(remaining, ...), so nothing waits pastdeadlineMs.Testing
stragglerGraceScalesBetweenFloorAndCeiling— unit-tests the window math directly across the threeregimes (floor / linear scale / ceiling), no timing.
manyHealthyChannelsSlowerThanGraceFloorAllConnect— 48 channels (MAX_CONNECT_THREADS * 3) on the16-worker pool, every connect healthy but 3 s (> the 2 s floor). Asserts all 48 connect; a fixed 2 s
window counts only ~16/48.
mixedLatencyUnderCountsAndIsNotFixedByTheCeiling— documents the benign mixed-latency under-countabove.
oneStuckChannelDoesNotHoldStartupForTheWholeBudgetand the other existing grace-window cases stillhold — a genuine straggler still releases at the (now floor-scaled-or-capped) window, not the whole budget.
BrokerServerPreConnectIntegrationTestandTlsIntegrationTestare unaffected: everything there connectsin milliseconds, so
2 * Lstays under the floor and no grace window ever expires.Backward compatibility
No config keys, metrics, wire protocol, or public API change.
STRAGGLER_GRACE_CAP_MSis a new internalconstant. Behaviour differs from #19407 only in the many-channels-slower-than-floor case, where it now waits
through the completion waves (still budget-bounded and ceiling-bounded) instead of under-counting.