Repository navigation
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
perf(cache,node): batch admit-time outboard capture into one wake (#1790
perf(cache): protect a partial once per fill, not per range admit (#1790
alpergundogdu commentedon Aug 31, 2026
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").Peerleg.populate_localowner vs a full-chainPeerwaiter); sharing the owner's failure blindly yields wrong answers. The amplification is instead bounded by the per-origin circuit breaker (failure_thresholdbudgets 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.
perf(node,cache): answer per-leaf serve presence from the held watch (#…
perf(cache): allocate the fill outboard buffer lazily, off the regist…
perf(cache): capture serve proof nodes during import, drop the export…
alpergundogdu commentedon Aug 31, 2026
Closing — the high-value work shipped, the rest deferred
Landed the common-path wins, one focused PR per item:
capture_many, one wake per admit)protect_partialtag once per fill, not per range admitPresentRangeWatch(no store hop); takedown via in-memoryrefusesFillRegistrylockexport_baoread-backItem 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)
Arclease so liveness/teardown skip the global registry map). Coupled — ADR 003: Specify EIP-712 domain separator for voucher signatures #8's literal fix reopens the Remove speculative client-less background warm (unpaid-egress → paid-ingress deposit-drain surface) #1610 resurrection race, so they must be designed together. Most of their value was already drained by items 7 and 1 (the notify storm is gone and theclaimcritical section is now O(1)), so what remains is scalability headroom that doesn't bite at current scale.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.
Merge origin/main into feat/1841-per-signer-floor-isolation