Repository navigation
feat(node): load-shedding under resource pressure (#1756) - #1767
Conversation
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-miss, per-client) Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
… slot Co-Authored-By: Claude Opus 4.8 <[email protected]>
…nt desync Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
… feed Co-Authored-By: Claude Opus 4.8 <[email protected]>
…airness), observe ShedReason Co-Authored-By: Claude Opus 4.8 <[email protected]>
Resolve config re-export list conflict as a union: keep load-shed (LoadShedPolicyKind, ResolvedLoadShed) and main's ResolvedTinyLfu. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds a node-side, content-agnostic load-shedding gate to refuse new paid serves under resource pressure (to protect in-flight streams), while keeping the wire behavior unchanged by reusing the existing NotFound-shaped rejection.
Changes:
- Introduces a pluggable
load_shedmodule (LoadShedPolicy,LoadShedController, egress EWMA meter, and concurrency/fairness counters) withAlwaysAdmitandResourcePressureimplementations. - Wires the load-shed gate into the client
serve_streampath and adds periodic egress EWMA sampling + new metrics for shed decisions and pressure state. - Adds
[load_shed]config support (resolved defaults + hot-reload section) and updates CLI sample config + tests to include the new resolved config field.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/tests/support/mod.rs | Updates loopback fixtures to use an always-admit load-shed controller. |
| crates/node/tests/sighup_signal.rs | Seeds resolved config with load_shed defaults for tests. |
| crates/node/tests/anvil_bringup_shutdown_e2e.rs | Seeds resolved config with load_shed defaults for e2e bringup tests. |
| crates/node/src/runtime/reload.rs | Adds a reloadable [load_shed] section and attaches a live controller for hot policy swaps. |
| crates/node/src/runtime/mod.rs | Builds and shares a LoadShedController, spawns periodic egress EWMA sampling, and wires shutdown handling. |
| crates/node/src/metrics.rs | Adds load-shed counters/gauges and a scrape test to validate they appear. |
| crates/node/src/load_shed/state.rs | New RAII-backed node-wide + per-client in-flight serve counters. |
| crates/node/src/load_shed/resource_pressure.rs | New ResourcePressure policy (hysteresis, egress ceiling, miss-before-hit, fairness under pressure). |
| crates/node/src/load_shed/mod.rs | New module entrypoint, shared types, and AlwaysAdmit policy. |
| crates/node/src/load_shed/egress.rs | New lock-free egress EWMA meter used by the policy + metrics. |
| crates/node/src/load_shed/controller.rs | New controller tying policy + state + egress meter together with hot-swappable policy. |
| crates/node/src/lib.rs | Exposes the new load_shed module from the node crate. |
| crates/node/src/handlers/client/wire.rs | Adds metric recording for the new load-shed rejection reasons. |
| crates/node/src/handlers/client/serve_leg.rs | Records egress bytes from the window-paced miss serve path. |
| crates/node/src/handlers/client/mod.rs | Adds new rejection reasons and threads the load-shed controller through handler deps. |
| crates/node/src/handlers/client/dispatch.rs | Wires the load-shed admission gate into serve_stream for both hit/miss paths. |
| crates/node/src/handlers/client/delivery.rs | Records egress bytes from the direct cache-hit delivery path. |
| crates/common/src/config/types.rs | Adds TOML [load_shed] config types and top-level FileConfig.load_shed. |
| crates/common/src/config/resolved.rs | Adds resolved load-shed config (ResolvedLoadShed, LoadShedPolicyKind) to ResolvedConfig. |
| crates/common/src/config/mod.rs | Adds load-shed defaults + resolver (resolve_load_shed_into) and integrates into config resolution. |
| crates/cli/tests/config_validate.rs | Updates CLI config validation test fixture resolved config to include load_shed. |
| crates/cli/src/commands/config.rs | Adds [load_shed] to the generated default config template and section presence checks. |
Suppressed comments (4)
crates/node/src/metrics.rs:1233
- The
serve_stream_rejected_load_shed_hitmetric doc currently implies it only tracks egress saturation, but cache-hit requests can also be shed due to per-client fairness while pressured. The metric appears to be hit-vs-miss classification, with the specificShedReasonlogged separately.
This issue also appears on line 2057 of the same file.
// Driven off `ALL` and destructured positionally so a new variant
// cannot compile without being materialized here — see `ALL`'s docs.
let [
crates/node/src/metrics.rs:2059
- The recorder doc for
serve_stream_rejected_load_shed_hitsays it's only egress saturation, but the hit path can also shed for per-client fairness under pressure. Consider describing this as "cache-hit shed" and leaving the reason toShedReasondebug logs.
down_seconds: blacklist_watcher_down_seconds;
/// The payment-settlement watcher's poll tick errored and the loop is about
crates/node/src/metrics.rs:2063
- The recorder doc for
serve_stream_rejected_load_shed_misscurrently lists only concurrency/fairness, but cache-miss requests can also be refused due to egress saturation (the policy sheds any class when saturated). Aligning the doc avoids under-reporting what this counter represents.
/// window. Mirrors [`Self::slash_watcher_backoff_started`].
settlement_watcher_backoff_started,
/// Mark the payment-settlement watcher cycle established (#1316): clear
crates/node/src/metrics.rs:1236
- The
serve_stream_rejected_load_shed_missmetric doc currently omits that cache-miss requests can also be shed due to egress saturation (the policy sheds any class when egress is saturated). This metric is about miss-vs-hit classification, not the specific shed reason.
This issue also appears on line 2061 of the same file.
probe_hold_exhausted,
probe_hold_disabled,
probe_hold_stake_lane_reserved,
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…edMiss reasons Egress meter/controller docs said 'wire bytes' but record the delivered bao-stream chunk length (content + proof), not the full QUIC frame — reword to match. LoadShedMiss doc now also lists egress saturation. Document why the policy uses ArcSwap<Arc<dyn LoadShedPolicy>> (arc-swap RefCnt requires Sized, so ArcSwap<dyn ...> does not compile). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 81.28% (was 81.15%, ▲ +0.12%) — 60316/74211 lines
History
|
… + hit refusals) Co-Authored-By: Claude Opus 4.8 <[email protected]>
What & why
Adds the third serve-time axis for deCDN nodes: load-shedding under resource pressure (issue #1756), alongside admission/eviction (ADR 040, #1754) and economic refuse-to-serve (#1755). When a node is physically saturated it refuses new paid serves — content-agnostic, regardless of blob or price — so in-flight streams stay fast and tail latency stays bounded. A refusal reuses the existing
NotFoundreject shape, so the client re-routes via the wired ADR 037 / #1174 failover at only a latency cost; shedding is not slashable and carries no reputation penalty.Design spec and plan live outside the repo (in
~/Workspace/decdn/specs, per repo convention).How it works
crates/node/src/load_shed/), mirroring the ADR 040 eviction/admission split: a pureLoadShedPolicytrait (decide(class, snapshot) -> Admit | Shed), unit-testable without a running node. Two implementations:AlwaysAdmit— a first-class NoOp for operators who want no heuristic shedding (the OS is then the only backstop; the pre-existingConnectionLimitertask caps still apply beneath it).ResourcePressure— hysteresis over node-wide concurrency, a hard egress ceiling, hit-before-miss priority (a cache hit is local/zero-upstream-cost, shed last; a miss fronts origin/upstream cost, shed first), and a per-client fair-share cap that engages only under actual pressure (no client is throttled because another might arrive).EgressMeter(bytes/sec EWMA) fed from the delivery hot path, plus node-wide and per-client in-flight counters with an RAIIShedSlotthat releases on every exit.PressureSnapshotis an additive seam — CPU/disk/eviction-churn signals can be added later without touching the gate or the wire.LoadShedControllerties the swappable policy (ArcSwap) + counters + egress meter into one handle the serve path holds; hot-reloadable.declaredMbpsis a commitment, never a live gate.serve_stream(dispatch.rs), aftercache.has(hit vs miss known) and after the eviction check, before any origin spend. Refusals collapse toStreamError::NotFound(LoadShedHit/LoadShedMissare metric-only distinctions) — no wire change.[load_shed]block (policy,egress_budget_mbps,max_concurrent_serves_high/_low,per_client_serve_cap), hot-reloadable via a newReloadableSection.serve_stream_rejected_load_shed_{hit,miss}counters,load_shed_egress_bps+load_shed_pressure_activegauges, and atracing::debug!at each shed site carrying theShedReason(egress-saturation vs concurrency vs per-client fairness).Notable
StreamErrorvariant — clients fail over transparently.ShedSlotbefore its later ownership refusal; this is bounded byConnectionLimiterand self-limiting (once pressured, further such requests shed at the gate without acquiring a slot). Aknown_lane-guarded gate is recorded as a possible future refinement.AlwaysAdmittest scaffolds keep existing serve tests unperturbed.Testing
cargo nextest run -p decdn-nodegreen (914 tests); anvil-e2e compiles; full-workspaceclippy/doc/deny/fmtpre-commit gate green.node_origin_pulltests are known load-dependent flakes under heavy parallel load (they pass in isolation) — unrelated to this change.🤖 Generated with Claude Code