Skip to content

coord/gateway/cluster: adaptive limiter + 429 shed (v0.12 phase 4) - #5

Merged
incognick merged 1 commit into
mainfrom
v0.12-adaptive-shed
Jun 29, 2026
Merged

coord/gateway/cluster: adaptive limiter + 429 shed (v0.12 phase 4)#5
incognick merged 1 commit into
mainfrom
v0.12-adaptive-shed

Conversation

@incognick

Copy link
Copy Markdown
Contributor

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:

  • Dynamic limit (AIMD gated by the Phase-3 gradient): grows additively while the gradient shows headroom (>= 0.5), shrinks multiplicatively as queuing inflates latency. Clamped [4, 256]start=16.
  • Shed at admission: tryAcquire is the first thing a PUT/GET does, before any placement/EC/encryption. Over the limit → immediate coord.ErrShed, no work done.
  • 429, distinct from 503: ErrShedErrTooManyRequests429 Too Many Requests + Retry-After. The 503 SlowDown durability-floor / non-leader path is unchanged — "at capacity, retry" vs "cannot write safely now."

Invariants verified (independently, in the diff):

  1. Shedding only refuses new requests — admitted/committed objects untouched, durability untouched, 429 fully retryable.
  2. Floor 4 → limit can never reach 0; forward progress guaranteed.
  3. release is unconditional in the single-fire done wrapper (every beginPut error path + both op.abort paths fire done), and the sim test asserts in-flight drains to 0 — no leak.
  4. Loop-owned + deterministic.

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), gateway TestShedMapsTo429 + TestUnavailableStillMapsTo503. task check/build/test + -race + e2e green; nothing sheds under the e2e's light load.

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>
@incognick
incognick enabled auto-merge June 29, 2026 03:23
@incognick
incognick added this pull request to the merge queue Jun 29, 2026
Merged via the queue into main with commit e913203 Jun 29, 2026
7 checks passed
@incognick
incognick deleted the v0.12-adaptive-shed branch June 29, 2026 03:32
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