Skip to content

fix(cache,client-pull,node): stream cold two-leg misses at bandwidth (#2061) - #2116

Merged
thiras merged 3 commits into
mainfrom
fix/2061-spine-pull-leg
Sep 22, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/2061-spine-pull-leg

Conversation

@thiras

@thiras thiras commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2061. A cold decdn bundle pull of a multi-GB bundle started at 40–60 MiB/s and then fell to 1–8 MiB/s. That happened once the pull reached content that only one node (bcl) could fill from its origin. Grafana and Loki show the cause:

  • Tiny upstream requests. fra1 opened a new upstream stream to bcl every ~5 s. The requests alternated between 1,097,728 bytes (PULL_WINDOW_FLOOR) and 5–66 MB. Every PaceDecision::Draw in drive is a new source.open().
  • Outboard re-read on every draw. bcl read the whole {H}.obao4 again on each draw, ~19 MB for a 4.8 GB blob. It counted 25.2 GB of pull_through_bytes for 10.2 GB served.
  • No time limit on origin reads. Nothing bounded a hung origin read on this path.

Changes

Outboard cache (crates/cache/src/outboard_cache.rs, engine.rs, origin_range.rs)

  • A 256 MiB memory cache of outboards. Each entry is keyed by hash, evicts the least recently used by bytes, and records which origin served it.
  • The dispatcher's "can this origin serve it" check and every draw read from it.
  • Each draw takes the outboard and the data from the same origin, trying the cached origin first. An orphaned, corrupt outboard on one origin can't fail another origin's data.
  • A hit is checked against the expected length.
  • On a verify fault, only the copy the failed draw used is evicted.

Minimum draw (crates/client-pull/src/pacer.rs)

  • Once the window is at least MIN_DRAW_WINDOW (4 × PULL_WINDOW_FLOOR), WindowPacer returns WaitForMinDraw until half the window is open.
  • A draw for a parked serve leg (serve demand) and the last piece of a gap are exempt.
  • The rule only turns draws into waits, so the exposure bound doesn't change.
  • PacingWait::wait now takes a WaitReason, so the two kinds of pause are counted separately.

Origin read time budget

  • Each origin read on this path (one outboard fetch, or one data window of at most 4 MiB) gets node_pull_stall_window_sec plus its size at node_pull_min_throughput_bps.
  • The budget grows with the read, so it doesn't limit blob size. There is no new config setting.
  • min_throughput_bps = 0 leaves these reads unbounded.

New metrics

  • decdn_cache_origin_range_timeouts_total
  • decdn_node_pull_through_min_draw_waits_total, counted separately from window_paused

Docs: ADR 037, appendix-observability, the stall-window and min-throughput setting docs plus the DEFAULT_CONFIG template, and the CHANGELOG.

Behaviour change: the dispatcher's check can now answer "yes" from a cached outboard without asking the origin. The live origin_size probe still confirms the data object exists. A later draw that the origin declines fails the stream after it is signed.

Test plan

  • cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check, cargo doc -D warnings, pre-commit
  • cargo nextest run -p decdn-client-pull -p decdn-cache -p decdn-node -p decdn-common -p decdn-cli: 3236/3236
  • New drive test with a large window, run with and without serve demand. Every open except the last is at least half the window, the number of opens is bounded, and the pull completes. It fails with the rule switched off.
  • Engine tests:
    • the outboard is read once per hash;
    • a verify fault forces a re-read;
    • a stuck outboard fetch or stuck first window moves on to the next origin;
    • a stuck later window times out;
    • an origin with no data doesn't lend its outboard;
    • outboard metering;
    • a wrong-length outboard is a hard fault.
  • Node integration test: exactly one .obao4 GET for a whole-blob own-origin miss.
  • Node-level tests not added: a 12 MiB end-to-end pull and a check that the runtime wires the time budget.
  • After redeploy, re-run the same bundle pull. On bcl, pull_through_bytes should roughly match bytes served, and its upstream draws should no longer be ~1 MiB.

Prefetching the next draw (#2061 §2.3) is left as a follow-up.

🤖 Generated with Claude Code

…2061)

A proxy-warmed bundle pull fell from 40-60 MiB/s to 1-8 MiB/s once it
reached content only one node could fill: every draw of the two-leg
serve-miss spine re-read the whole {H}.obao4 outboard from the origin,
and the window pacer opened a new upstream request for each small piece
of room a voucher released.

- cache: a 256 MiB outboard cache keyed by hash and tagged with the
  serving origin. The serviceability probe and every draw read it; each
  draw takes outboard and data from the same origin; a verify fault
  evicts the copy the draw used; a hit is length-checked.
- client-pull: WindowPacer waits (WaitForMinDraw) until half a window of
  at least four pull-window floors is open, except for a serve-demand
  draw or the gap tail. Exposure bound unchanged.
- cache/node: each origin read on the range-pull path gets a budget of
  node_pull_stall_window_sec plus its size at node_pull_min_throughput_bps.
- metrics: decdn_cache_origin_range_timeouts_total and
  decdn_node_pull_through_min_draw_waits_total.
- ADR 037, appendix-observability, config docs, CHANGELOG.

Closes #2061

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 22, 2026 15:23
@thiras thiras self-assigned this Sep 22, 2026

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.

Copilot review overview

🟡 Changes recommended

Resolve the cache coalescing, zero-byte eviction, and gap-accounting issues.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Improves cold multi-GB pulls by reusing outboards, batching draws, and bounding origin reads.

Changes:

  • Adds origin-affine, byte-bounded outboard caching.
  • Enforces minimum draw sizes and adds pacing metrics.
  • Adds origin-read budgets, tests, metrics, and documentation.
File Reviewed change
crates/​node/​tests/​origin_range_pull.rs Verifies one outboard request per pull.
crates/​node/​src/​runtime/​mod.rs Wires origin-read budgets.
crates/​node/​src/​node_origin/​pull_leg.rs Separates pacing wait metrics.
crates/​node/​src/​node_origin/​backend_source.rs Updates origin failure messaging.
crates/​node/​src/​metrics.rs Adds minimum-draw metrics.
crates/​node/​src/​handlers/​client/​dispatch.rs Documents cached serviceability behavior.
crates/​common/​src/​config/​types.rs Documents budget settings.
crates/​common/​src/​config/​resolved.rs Documents resolved budget fields.
crates/​client-pull/​src/​pacer.rs Implements minimum-draw pacing.
crates/​client-pull/​src/​lib.rs Exports pacing APIs.
crates/​client-pull/​src/​driver.rs Handles wait reasons and adds tests.
crates/​cli/​src/​commands/​config.rs Updates default configuration documentation.
crates/​cache/​src/​outboard_cache.rs Adds the bounded outboard cache.
crates/​cache/​src/​origin/​mod.rs Updates the origin contract.
crates/​cache/​src/​origin_range.rs Adds cached outboards and read timeouts.
crates/​cache/​src/​metrics.rs Adds origin-timeout metrics.
crates/​cache/​src/​lib.rs Registers the cache module.
crates/​cache/​src/​engine.rs Integrates caching, fallback, and budgets.
CHANGELOG.md Records the performance fix.
adr/​appendix-observability.md Documents new metrics.
adr/​037-regional-proxy-warming.md Updates range-pull behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/outboard_cache.rs Resolved
Comment thread crates/node/src/runtime/mod.rs Resolved
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.80% (was 83.69%, ▲ +0.11%) — 87606/104540 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 93.45% 5468/5851 ▲ +0.31%
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/cache/src/origin/mod.rs 63.64% 70/110 ● 0.00%
crates/cache/src/origin_range.rs 86.97% 387/445 ▼ 0.99%
crates/cache/src/outboard_cache.rs 99.41% 169/170 new
crates/cli/src/commands/config.rs 87.13% 792/909 ● 0.00%
crates/client-pull/src/driver.rs 94.79% 1801/1900 ▲ +0.14%
crates/client-pull/src/lib.rs 90.64% 1965/2168 ● 0.00%
crates/client-pull/src/pacer.rs 98.46% 383/389 ▲ +0.03%
crates/common/src/config/resolved.rs 100.00% 42/42 ● 0.00%
crates/common/src/config/types.rs 100.00% 18/18 ● 0.00%
crates/node/src/handlers/client/dispatch.rs 81.62% 524/642 ● 0.00%
crates/node/src/metrics.rs 95.18% 1087/1142 ● 0.00%
crates/node/src/node_origin/backend_source.rs 90.16% 330/366 ● 0.00%
crates/node/src/node_origin/pull_leg.rs 87.07% 788/905 ▲ +0.41%
crates/node/src/runtime/mod.rs 48.37% 1190/2460 ▲ +0.47%
History
Commit Total Δ vs base
92f2792 83.79% ▲ +0.09%
4c5382e 83.80% ▲ +0.11%
2b00adb (HEAD) 83.80% ▲ +0.11%

…oard cache

- Concurrent cold misses of one hash wait on a per-hash flight lock and
  reuse the first origin read's cached copy, so a burst of probes before
  claim_fill no longer multiplies outboard egress.
- The outboard cache skips empty outboards (a one-group blob has none)
  and caps its entry count at 4096, bounding the map and the O(n)
  eviction scan.
- build_cache is tested to wire the origin read budget from
  node_pull_stall_window_sec / node_pull_min_throughput_bps.

Co-Authored-By: Claude Opus 5 (1M context) <[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.

Copilot review overview

🟡 Changes recommended

Two moderate findings in crates/cache/src/engine.rs remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
Resolved since last review (3)

Comment thread crates/cache/src/origin/mod.rs Resolved
@thiras
thiras merged commit 8a32f7d into main Sep 22, 2026
25 checks passed
@thiras
thiras deleted the fix/2061-spine-pull-leg branch September 22, 2026 16:23
alpergundogdu added a commit that referenced this pull request Sep 22, 2026
Resolve the #2116 × #1848 overlap in client-pull:
- lib.rs re-exports: keep both the #1848 `downloader::{DownloadTarget,
  Downloader}` line and #2116's added `WaitReason` on the `driver` re-export.
- #2116 gave `PacingWait::wait` a third `reason: WaitReason` arg (metering
  only). Update the two #1848 impls to the new signature: `ConsumedWait`
  (streamer.rs) and the `BumpConsumer` test double (scheduler.rs), taking
  `_reason` since neither meters.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants