Skip to content

fix(quic): coalesce twin admissions into one snapshot so a pod's first use of many QUIC destinations fits the on_demand window (#1086) - #1102

Merged
bpalermo merged 2 commits into
mainfrom
fix/1086-coalesce-twin-admissions
Oct 1, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/1086-coalesce-twin-admissions

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Closes #1086

What was failing

When a pod's identity dials 7–10 QUIC destinations for the first time at once (the k6 loader start), some requests fail with 503 NC cluster_not_found. This happened on three soaks: 116, 141 and 66 failures.

Timeline: main-worker-05, 2026-10-01T00:36Z (51 of the 66)

Sources: Envoy cm odcds and cds: lines, agent lines, access-log start_time, and Pyroscope for the agent.

t (00:36:…Z) event
28.626 – 28.738 First requests reach the proxy: svc-2, svc-3, then svc-1, mixed-svc, echo and svc-4. Each opens an ODCDS subscription for quic:…@aether-test/default.
28.716 / 28.783 The agent admits svc-2 and svc-3.
28.751 → 28.947 Snapshot 58 (a registry refresh) runs SetSnapshot plus identity logging.
29.113 – 29.122 The agent admits svc-1, mixed-svc, echo and svc-4. These were requested at 28.645–28.738, so they arrived 0.4–0.47 s late. The ADS stream goroutine was stuck behind SetSnapshot holding the cache mutex.
29.035 → 29.43 Snapshot 59 delivers 2 twins (svc-2, svc-3). Those requests succeed, but with a maximum latency of 2.19 s.
29.516 → 30.14 Snapshot 60 delivers the other 4 twins. SetSnapshot alone took about 600 ms.
30.221 Envoy applies the CDS update (4 added). The twins now need EDS to warm.
30.246 → 31.118, then 62–65 More builds hold the cache mutex: 61 is a real change, 62–65 rebuild a snapshot with the same shape (108 clusters). The twins' EDS subscription requests queue behind them.
30.645 – 30.738 cm odcds: on-demand discovery … timed out fires for svc-1, echo, mixed-svc and svc-4. Every request waiting on those twins (including ones that joined late) gets 503 NC.

main-worker-02 (the other 15 failures) shows the same pattern. svc-4 was requested at 28.144, but the agent only admitted it at 29.046, 0.9 s later, after four back-to-back builds. Its twin reached Envoy at 30.78, after the 30.144 timeout.

Where the time goes

  • One full snapshot rebuild per admission. ObserveQUICTwin and ResumeQUICSubscriptions each started their own go generateSnapshot(). These serialize on snapshotMu. The first one already includes every pair recorded so far, because admission records the pair synchronously, so the rest are redundant.
  • Each build is expensive on talos. The agent's Pyroscope profile shows about 93% of generateSnapshot CPU in go-control-plane's respondDeltaWatches → ConstructVersionMap (deterministic proto marshal plus sha256 of every resource). That runs inside SetSnapshot under cache.mu. The agent is capped at 200m CPU, so a build takes 200–870 ms of wall clock.
  • The ADS stream goroutine contends for the same mutex. It needs cache.mu for every request (watch cancel plus CreateDeltaWatch). Redundant builds therefore delay both the arrival of later ODCDS requests and the EDS subscriptions a new twin needs before it can warm.
  • The 2 s budget is the route-level on_demand timeout. Raising it is not justified: the measured cost is the redundant work, not a one-off setup delay.

Fix

requestQUICPublish / runQUICPublisher in agent/internal/xds/cache/quicpublish.go:

  • At most one publish is pending and at most one is running.
  • The first admission of a burst waits a 10 ms window, then builds once.
  • An admission that arrives while a build is running marks the publish pending again, which triggers exactly one more build. The last build always starts after the last admission was recorded, so nothing recorded is left unpublished.
  • Result: N simultaneous admissions cost 1–2 builds instead of N.
  • ResumeQUICSubscriptions (re-subscriptions on a fresh stream) uses the same publisher.

Only the publish is coalesced. recordQUICPair still runs synchronously on the ODCDS request: it records the pair, confirms it (demand_confirmed, #1073/#1076), records the ledger subscription and persists it. The invariants are unchanged:

The on_demand timeout is unchanged.

Evidence

Unit test, red then green

TestQUICAdmissionBurstCoalesces: 10 simultaneous first-use admissions must cost ≤ 2 builds, and every twin must be published with its CLA in under 500 ms. The test file builds against main.

main: N=10 simultaneous admissions: 10 snapshot builds   -> FAIL "10" is not less than or equal to "2"
fix:  N=10 simultaneous admissions: 1 snapshot builds; all twins published after 11.2ms

BenchmarkQUICAdmissionBurst, under a systemd-run -p CPUQuota=20% scope (the agent's 200m cap):

builds/burst settled-ms/burst
main 10.0 37.9
fix 1.0 11.2

Also added in quicpublish_test.go:

  • An admission that arrives during an in-flight build gets exactly one more build.
  • A lone admission costs one build, after the window, and then the worker goes idle.
  • Resumed subscriptions cost one build.

kind, red then green

New leg E7 in e2e/eastwest-quic.sh (burst subcommand, also part of verify): a brand-new ServiceAccount sends 10 QUIC destinations × 5 concurrent requests the instant its app starts, with the identity gate on. It asserts 0 non-200 and reports p50/p99/max latency, admissions, coalesced publishes and snapshot builds (builds need EWQ_DEBUG=1).

Cluster aether-1086, same cluster for both. The agent image was swapped between main and the fix, each run used a fresh SA, and every row is a separate run:

agent builds per burst first-use p50 / p99 non-200
main 10, 10, 10 0.87/0.93, 0.63/1.11, 0.58/0.98 s 0
main (earlier cluster) 10, 10, 10, 20 (20 destinations) p99 1.56, 1.23, 1.23, 1.62 s 0
fix 2, 1, 2 0.21/0.23, 0.24/0.25, 0.45/0.55 s 0
fix (earlier cluster / full verify) 1, 2, 2, 1 p99 0.27, 0.40, 0.28, 0.22 s 0

kind never crossed the 2 s timeout on main, so there is no NC red here. The red is the build count (one per admission) and a 4–5× higher first-use p99. The full verify (E0–E7) is green with the fix.

Other checks: bazel test //agent/internal/xds/..., --config=race on agent/internal/xds/cache and agent/internal/xds/server, make gazelle, make format, and bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //... all pass. No charts/ change.

Open risks / follow-ups

  • Each build is still expensive. A single build that itself takes more than about 1.5 s still fails a burst. I saw this on kind when about 50 pods piled up on one 200m-capped agent: builds took 2–11 s and failed regardless of coalescing. Two levers, neither in this PR:
    • Memoize per-resource version hashes across snapshots. ConstructVersionMap is about 93% of build CPU. This is only safe if published protos are never mutated in place.
    • Revisit the agent's 200m CPU limit.
  • The 10 ms window adds 10 ms to a lone first use. A burst that straddles a build costs a second build. Both are bounded.
  • Builds triggered by registry refreshes still run alongside the burst. Only the twin-admission builds are coalesced.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…t use of many QUIC destinations fits the on_demand window (#1086)

A pod's identity dialling 7-10 QUIC destinations for the first time at once
(k6 loader start) produced 66-141 x 503 NC cluster_not_found per soak. Every
admitted `quic:` pair started its own goroutine running a full
generateSnapshot. They serialized on snapshotMu; the first already carried
every pair recorded so far, so the rest rebuilt and re-set the same snapshot
one after another. On talos each build is ~93% go-control-plane version-map
hashing (proto marshal + sha256 of every resource) inside SetSnapshot, under
the cache mutex, on an agent capped at 200m: 200-870 ms of wall clock each.
The ADS stream goroutine needs that same mutex for every request it handles,
so both the later ODCDS requests (received 0.47-0.9 s late) and the new
twins' EDS subscriptions (Envoy cannot warm the cluster without them) queued
behind the redundant builds. On main-worker-05, 2026-10-01T00:36:28-31Z: six
admissions, eight snapshot builds in 4.4 s, and four twins whose CDS add
landed at 30.14-30.22Z were still warming when their on_demand timeouts fired
at 30.645-30.738Z.

requestQUICPublish keeps at most one publish pending and one running: the
first admission of a burst waits 10 ms for the rest, then builds once; an
admission that arrives during the build forces exactly one more build. N
simultaneous admissions now cost 1-2 builds instead of N. Only the publish is
coalesced: recordQUICPair still records, confirms and persists the pair
synchronously, so the strand rule, the cert gate, demand_confirmed and the
stream-reset classification are untouched. ResumeQUICSubscriptions rides the
same publisher.

Proof: TestQUICAdmissionBurstCoalesces (10 simultaneous admissions, <= 2
builds) is red on main (10 builds) and green here (1). e2e/eastwest-quic.sh
gains E7, a new ServiceAccount's first use of 10 QUIC destinations x 5
concurrent requests: on kind, main 10 builds per burst and first-use p99
0.93-1.56 s; this change 1-2 builds and p99 0.22-0.55 s, 0 non-200 on both
(kind never crossed 2 s on main).

Closes #1086

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 86a7e0c into main Oct 1, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1086-coalesce-twin-admissions branch October 1, 2026 15:16
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.

quic: a new pod's first use of many QUIC destinations at once exceeds the 2 s on_demand timeout (503 NC burst at loader start)

1 participant