Repository navigation
Description
Group F of the serve-path hot-path audit (siblings: #1788–#1792). These run once per completed serve, so they look cheap per request — but they are the per-request touches on global mutexes that background scans hold for O(N), which is how completion latency becomes cache-size-dependent.
1. access_times: every completed serve contends with O(cache-size) scans under the same guard
Write side: record_access via observe_hit (engine.rs:108,3169-3189; called at delivery.rs:476 / serve_leg.rs:466). Scan side: eviction_candidates iterates and filters the whole map under the guard on the 1 s sweep (engine.rs:3133-3152), and access_times_snapshot full-clones under it (:3016-3021).
Fix: shard it (e.g. DashMap<Hash, atomic-instant>) so the serve path is one shard touch and the sweep walks shard-by-shard; or have the sweep swap the map out and merge. Interim: copy-then-filter under a short hold.
Improves: terminal bookkeeping becomes O(1) and uncontended; the eviction sweep stops stalling serves.
Leaving as-is limits: stream-completion tail latency grows with cached-blob count — the busier and fuller the node (the scale-up steady state), the longer every serve's final step can block behind a sweep holding the lock across the full map. Completion stalls also hold stream/session resources (lane slots, floor reservations, shed counters) longer than needed, inflating apparent concurrency.
2. TinyLFU: one process-wide mutex per completed serve, with an O(sketch) halving under it
crates/cache/src/policy/tinylfu.rs:15 (Mutex<CountMinSketch>), observe/estimate at :30-43; the periodic halving walks all ROWS×cols counters under the same lock (sketch.rs:47-52) every cols×10 observes. Admission (ProbationAdmission::admit, tinylfu.rs:58-65) shares the mutex from the fill path.
Fix: shard the sketch (per-shard mutex or atomic counters) and halve incrementally per shard.
Improves: frequency bookkeeping stops serializing all serve completions and fills node-wide.
Leaving as-is limits: any node configured with tinylfu (ADR 040) puts every completed serve of every hash through one mutex — a hard completion-rate ceiling — and takes a recurring latency spike, growing with sketch size, that lands on whichever serves complete during the halving. The policy exists for exactly the high-traffic nodes where this hurts most.
3. Warming credit takes a global two-map mutex on the stream task
warming_allowance.rs:55,119-130 (credit_warming_serve, called at delivery.rs:480 / serve_leg.rs:470), contended by the eviction driver and the warming buy loop.
Fix: ship the credit over a non-blocking channel to a background aggregator — the same pattern as the receipt sink — or shard per source.
Improves: the stream task sheds its last global-mutex touch at completion (after items 1–2).
Leaving as-is limits: serve completions contend with warming policy machinery (ADR 037/041 buy-loop bookkeeping); as warming activity scales with network size, an economics background job gains the ability to add jitter to every serve's final step.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity