coord/gateway/cluster: adaptive limiter + 429 shed (v0.12 phase 4) - #5
Merged
Conversation
Adds the v0.12 load shedder (ADR-0039 parts 3-4): a per-op (PUT/GET) adaptive
concurrency limiter on the coordinator loop, and admission shedding with HTTP
429. The limit is dynamic, not fixed — AIMD gated by the Phase-3 gradient: it
grows additively while the gradient shows headroom (>= 0.5) and shrinks
multiplicatively as queuing inflates latency, clamped to [4, 256] so it can never
reach zero (a floor that guarantees forward progress). tryAcquire is the first
thing a PUT or GET does, before any placement/EC/encryption; over the limit it
sheds immediately with coord.ErrShed and does no work. release runs on every
terminal via the single-fire done wrapper, so in-flight never leaks.
The gateway maps ErrShed to 429 Too Many Requests with Retry-After, kept
distinct from the 503 SlowDown durability-floor/non-leader refusal — 'at
capacity, retry' vs 'cannot write safely now.' Shedding only ever refuses a new
request: an admitted or committed object is never touched, and a 429 is fully
retryable (critical invariant 1). Loop-owned and deterministic, so the simulator
drives it.
New metrics: hamster_s3_request_{shed_total,limit,inflight}{method}.
Tests: limiter unit (acquire/release accounting, AIMD grow/shrink, clamp bounds,
no underflow), a coord sim proving surplus PUTs shed while admitted ones commit
and in-flight drains to 0, and gateway 429-vs-503 distinctness. task
check/build/test + e2e green; nothing sheds under the e2e's light load.
Signed-off-by: Nicholas Phillips <nsphilli@gmail.com>
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.
v0.12 adaptive load shedding — Phase 4 of 5 (ADR-0039 parts 3 + 4). The first phase that changes request behavior, so it's invariant-driven.
A per-op (PUT/GET) adaptive concurrency limiter on the coordinator loop, plus admission shedding with HTTP 429:
>= 0.5), shrinks multiplicatively as queuing inflates latency. Clamped[4, 256]—start=16.tryAcquireis the first thing a PUT/GET does, before any placement/EC/encryption. Over the limit → immediatecoord.ErrShed, no work done.ErrShed→ErrTooManyRequests→429 Too Many Requests+Retry-After. The503 SlowDowndurability-floor / non-leader path is unchanged — "at capacity, retry" vs "cannot write safely now."Invariants verified (independently, in the diff):
4→ limit can never reach 0; forward progress guaranteed.releaseis unconditional in the single-firedonewrapper (everybeginPuterror path + bothop.abortpaths firedone), and the sim test asserts in-flight drains to 0 — no leak.Constants (ADR leaves to impl):
floor=4,ceiling=256,start=16,increase=1,decrease=0.9,gradientShedThreshold=0.5— all commented.New metrics:
hamster_s3_request_{shed_total,limit,inflight}{method}.Tests: limiter unit (accounting, AIMD grow/shrink, clamp, no underflow), coord sim (
TestPutShedsAtAdmissionAndDrains— surplus PUTs shed while admitted ones commit, inflight→0, shedding then stops), gatewayTestShedMapsTo429+TestUnavailableStillMapsTo503.task check/build/test+-race+e2egreen; nothing sheds under the e2e's light load.