Skip to content

feat(node): load-shedding under resource pressure (#1756) - #1767

Merged
alpergundogdu merged 14 commits into
mainfrom
claude/loving-bardeen-2e339f
Aug 20, 2026
Merged

alpergundogdu merged 14 commits into
mainfrom
claude/loving-bardeen-2e339f

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

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 NotFound reject 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

  • Pluggable policy (crates/node/src/load_shed/), mirroring the ADR 040 eviction/admission split: a pure LoadShedPolicy trait (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-existing ConnectionLimiter task 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).
  • Signals (the cheap, preemptive 80/20): a lock-free rolling EgressMeter (bytes/sec EWMA) fed from the delivery hot path, plus node-wide and per-client in-flight counters with an RAII ShedSlot that releases on every exit. PressureSnapshot is an additive seam — CPU/disk/eviction-churn signals can be added later without touching the gate or the wire.
  • LoadShedController ties the swappable policy (ArcSwap) + counters + egress meter into one handle the serve path holds; hot-reloadable.
  • Capacity reference is a node-local config egress budget — the on-chain declaredMbps is a commitment, never a live gate.
  • Gate wired into serve_stream (dispatch.rs), after cache.has (hit vs miss known) and after the eviction check, before any origin spend. Refusals collapse to StreamError::NotFound (LoadShedHit/LoadShedMiss are metric-only distinctions) — no wire change.
  • Config: node-local [load_shed] block (policy, egress_budget_mbps, max_concurrent_serves_high/_low, per_client_serve_cap), hot-reloadable via a new ReloadableSection.
  • Observability: serve_stream_rejected_load_shed_{hit,miss} counters, load_shed_egress_bps + load_shed_pressure_active gauges, and a tracing::debug! at each shed site carrying the ShedReason (egress-saturation vs concurrency vs per-client fairness).

Notable

  • No wire/ABI change, no new StreamError variant — clients fail over transparently.
  • The gate is content-/payment-agnostic by design. An unbound/unknown-lane request may transiently hold a ShedSlot before its later ownership refusal; this is bounded by ConnectionLimiter and self-limiting (once pressured, further such requests shed at the gate without acquiring a slot). A known_lane-guarded gate is recorded as a possible future refinement.
  • Anti-panic clean across all non-test code; AlwaysAdmit test scaffolds keep existing serve tests unperturbed.

Testing

  • Per-module unit tests for the policy (hysteresis, hit-before-miss, the no-speculative-reservation fairness invariant, zero-disables semantics), the egress EWMA math, the RAII counters (incl. a prune-then-recreate regression), the controller (live policy swap, egress→snapshot), config resolver, metrics scrape, and the reload section.
  • Full cargo nextest run -p decdn-node green (914 tests); anvil-e2e compiles; full-workspace clippy/doc/deny/fmt pre-commit gate green.
  • Note: node_origin_pull tests are known load-dependent flakes under heavy parallel load (they pass in isolation) — unrelated to this change.

🤖 Generated with Claude Code

alpergundogdu and others added 11 commits August 20, 2026 11:31
…airness), observe ShedReason

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 20, 2026 13:47
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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_shed module (LoadShedPolicy, LoadShedController, egress EWMA meter, and concurrency/fairness counters) with AlwaysAdmit and ResourcePressure implementations.
  • Wires the load-shed gate into the client serve_stream path 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_hit metric 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 specific ShedReason logged 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_hit says 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 to ShedReason debug 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_miss currently 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_miss metric 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.

Comment thread crates/node/src/load_shed/controller.rs Resolved
Comment thread crates/node/src/load_shed/controller.rs Resolved
Comment thread crates/node/src/load_shed/egress.rs Resolved
Comment thread crates/node/src/load_shed/egress.rs Resolved
Comment thread crates/node/src/load_shed/controller.rs Resolved
Comment thread crates/node/src/handlers/client/mod.rs Resolved
…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]>
@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.28% (was 81.15%, ▲ +0.12%) — 60316/74211 lines

File Coverage Lines Δ
crates/cli/src/commands/config.rs 86.35% 525/608 ▲ +0.05%
crates/common/src/config/mod.rs 97.06% 6735/6939 ▼ 0.03%
crates/common/src/config/resolved.rs 100.00% 42/42 ● 0.00%
crates/node/src/handlers/client/delivery.rs 95.93% 236/246 ▲ +0.02%
crates/node/src/handlers/client/dispatch.rs 85.22% 421/494 ▲ +0.92%
crates/node/src/handlers/client/mod.rs 92.18% 1190/1291 ▲ +0.28%
crates/node/src/handlers/client/serve_leg.rs 85.89% 140/163 ▲ +0.09%
crates/node/src/handlers/client/wire.rs 97.67% 126/129 ▲ +0.04%
crates/node/src/load_shed/controller.rs 100.00% 106/106 new
crates/node/src/load_shed/egress.rs 100.00% 46/46 new
crates/node/src/load_shed/mod.rs 100.00% 21/21 new
crates/node/src/load_shed/resource_pressure.rs 100.00% 102/102 new
crates/node/src/load_shed/state.rs 100.00% 91/91 new
crates/node/src/metrics.rs 94.44% 850/900 ▲ +0.09%
crates/node/src/runtime/mod.rs 47.89% 1090/2276 ▼ 0.34%
crates/node/src/runtime/reload.rs 96.47% 1504/1559 ▼ 0.31%
History
Commit Total Δ vs base
1005af4 81.26% ▲ +0.11%
dbac317 81.26% ▲ +0.96%
d80a889 (HEAD) 81.28% ▲ +0.12%

@alpergundogdu
alpergundogdu merged commit c9d5997 into main Aug 20, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/loving-bardeen-2e339f branch August 20, 2026 15:18
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.

Load-shedding under resource pressure (bandwidth / cache pressure)

2 participants