Skip to content

perf(cache,node): miss/fill path — FillRegistry global serialization, per-leaf re-admission, admit-time amplification #1790

Closed

Description

@alpergundogdu

Group C of the serve-path hot-path audit (siblings: #1788 accept, #1789 TTFB; doc drift: #1787). These items govern pull-through serves — miss TTFB and mid-stream miss throughput — and the degree to which concurrent misses interfere with each other.

1. make_session() allocates the outboard buffer under the global registry lock

crates/cache/src/fill_session.rs:868-957 — claim() holds FillRegistry.map (one process-wide std::Mutex) across make_session, which zeroes vec[0u8; blob/256] (:136-150) — ~2.7 MB for a 700 MB blob. The attach path then discards its freshly allocated buffer and adopts the canonical one (:776-780).

Fix: allocate before locking, insert under the lock; skip the allocation entirely on the attach path.

Improves: the registry critical section becomes O(1); no MB-scale zeroing under a global mutex; no wasted allocations on attach.

Leaving as-is limits: a single large-blob miss stalls every other miss's claim, parked-reader wakeup, and teardown for the allocation duration. Concurrent large-blob misses convoy on the registry — miss-path concurrency stops scaling with blob size, which is backwards.

2. range_still_live takes the global registry mutex on every parked-reader wakeup

fill_session.rs:824-831, called from the serve encoder's park loop (serve_encoder.rs:121).

Fix: give each ObserverLease an Arc to its per-hash entry so liveness checks never touch the global map.

Improves: wakeup checks become per-hash and lock-free with respect to other hashes.

Leaving as-is limits: N stalled serve streams × wakeup rate all serialize on one process mutex, and item 7's notify storm multiplies the wakeup rate — cross-hash interference grows superlinearly with concurrent misses, capping how many pull-throughs a node can run at once.

3. The encoder re-runs admission and 2–3 store round trips per 16 KiB leaf

serve_encoder.rs:88 → engine.rs:1655/1558-1576 (present_ranges → refuses: deny sets + the evicted mutex + 2 store-actor hops), plus a third hop in read (engine.rs:3352) — ~190 store round trips per MiB served on the miss path.

Fix: enforce deny/takedown at its own cadence (per collected proof, ADR 011) instead of per leaf, and answer presence from the PresentRangeWatch subscription the reader already holds (engine.rs:1599-1634).

Improves: per-leaf cost drops to a local range check; miss-path streaming throughput stops being bounded by store-actor message rate.

Leaving as-is limits: pull-through throughput is capped by actor round-trip latency rather than by disk or network — the gap widens as upstream bandwidth improves, and the per-leaf evicted mutex touch multiplies the contention in #1789 item 5.

4. Post-admit export_bao read-back to recover proof nodes

engine.rs:2928 (outboard_pairs) — every range admit re-reads through the store actor what the import just decoded.

Fix: capture proof nodes during import.

Improves: halves store traffic per admit; captured wakeups reach parked serve legs sooner, cutting miss TTFB and inter-chunk gaps.

Leaving as-is limits: first-byte on pull-through waits on a redundant read-back, and fill-time store load is doubled — the node's own fills compete with its serves for the store actor.

5. protect_partial tag write per range admit

engine.rs:1814-1823, called at :2588,:2786,:2918.

Fix: write the partial-protection tag once per blob per fill (it only needs to exist).

Improves: removes a tag-table write from every admit.

Leaving as-is limits: store write load grows with fill size for no added protection — write amplification that steals store-actor time from concurrent serves.

6. Retry backoff holds the breaker TrialGuard and the inflight coalescing entry

crates/cache/src/retry.rs:219 sleep inside engine.rs:3716-3740.

Fix: propagate the failure to coalesced waiters immediately (let them re-drive selection), or release the entry before sleeping.

Improves: same-hash requesters fail over at fault time instead of after the backoff.

Leaving as-is limits: every requester coalesced on a flaky origin's blob silently parks for the whole backoff — user-visible multi-second TTFB on popular content behind one slow origin; the coalescing that should protect the origin instead multiplies client-facing latency.

7. Admit-time notify storm: per-node × per-reader wakeups

engine.rs:2932-2934 loops over all captured outboard pairs; each capture fires notify_waiters (fill_session.rs:174), waking every parked reader of that hash, per node.

Fix: batch: notify once per admit.

Improves: wakeups per admit drop from N readers × M nodes to N.

Leaving as-is limits: popular content — many attached readers — is exactly where the storm is worst; until item 2 lands, every spurious wakeup is also a global-mutex acquisition, so popularity converts directly into registry contention.

8. ObserverLease::teardown does cancel/notify/join-handle work under the global lock

fill_session.rs:592-633, running from Drop on arbitrary runtime workers.

Fix: remove the entry under the lock; run cancel(), notify_waiters(), and the nested pull_thread access after release.

Improves: teardown's global critical section becomes a map remove.

Leaving as-is limits: disconnect bursts (client churn, failover waves) stall the entire miss path behind teardown work — the moment the node is under stress is the moment claims and wakeups queue.

9. Discovery → funding → handshake run serially before the signed response

window.rs:151 → node_origin: DHT FIND_VALUE, then the probe collection window (500 ms ceiling, ADR 005), then buyer channel open/top-up, then the upstream header handshake.

Fix: overlap probing with channel funding for the best-known candidate; lean on the probe/RTT caches for the front half.

Improves: miss TTFB approaches max(discovery, funding) instead of their sum.

Leaving as-is limits: cold-miss TTFB carries the full serial sum on every fill; at scale-out (more namespaces, colder caches) this fixed serial cost dominates the user-visible latency of first requests.

Related: #1787, #1788, #1789.

Activity

  1. moved this from Backlog to Ready in deCDNon Aug 24, 2026
  2. added
    rust
    prio:medium
    on Aug 26, 2026
  3. alpergundogdu commented on Aug 31, 2026

    @alpergundogdu
    ContributorAuthor

    Item 6 — not pursuing (already-considered). Traced the coalescing/backoff path: the fix as written collides with a deliberate, documented decision in crates/cache/src/retry.rs (the module doc under "Coalescing interaction and the retry-amplification bound").

    • "Release the entry before sleeping" would let a waiter re-elect and pull concurrently with the owner's still-running retry loop — the cache: concurrent origin pull-through for the same hash can result in duplicate fetches and redundant insertions into iroh-blobs #305 double-pull, i.e. duplicate origin egress and duplicate USDC on the paid Peer leg.
    • "Propagate the failure to waiters" is rejected there because coalesced waiters don't share origin reach (a populate_local owner vs a full-chain Peer waiter); sharing the owner's failure blindly yields wrong answers. The amplification is instead bounded by the per-origin circuit breaker (failure_threshold budgets per window, independent of N) — a pinned, tested invariant.

    The module explicitly states the tighter bound is "deliberately NOT implemented … not worth its risk on this hot, cancellation-sensitive path." Leaving item 6 as-is; reopen if the circuit-breaker bound proves insufficient in practice.

  4. alpergundogdu commented on Aug 31, 2026

    @alpergundogdu
    ContributorAuthor

    Closing — the high-value work shipped, the rest deferred

    Landed the common-path wins, one focused PR per item:

    Item Fix PR
    7 Batch the admit-time notify storm (capture_many, one wake per admit) #1879
    5 Write the protect_partial tag once per fill, not per range admit #1882
    3 Answer per-leaf serve presence from the held PresentRangeWatch (no store hop); takedown via in-memory refuses #1883
    1 Allocate the fill outboard buffer lazily, off the FillRegistry lock #1884
    4 Capture serve proof nodes during import; drop the export_bao read-back #1886

    Item 6 — not pursued (see the earlier comment): both proposed fixes collide with a deliberate, documented decision in retry.rs (coalescing correctness / USDC double-spend); the per-origin circuit breaker already bounds the amplification.

    Deferred (low value now, will re-evaluate later)

    Neither is worth its invasiveness today. Closing as completed; will file a fresh issue if/when 2+8 or 9 earn their keep at scale.

  5. moved this from Ready to Done in deCDNon Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:mediumrust

Type

No type

Fields

Priority

High

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions