Repository navigation
Description
Group H of the serve-path hot-path audit (siblings: #1788–#1794; doc drift: #1787). Nothing here is on the serve path itself — these are the background tasks that periodically grab locks the serve path needs. The fix direction is always the same: keep the background work, change which lock it holds and for how long. Items 1–2 are largely subsumed by #1792 item 1 (per-lane dirty cells) but are independently and cheaply fixable if that lands later.
1. The periodic flush postcard-encodes every dirty lane under the LaneBuffer mutex
channel_store.rs:738-755 — the 5 s flush task (runtime/mod.rs:503-530) snapshots and encodes all dirty lanes while holding the same global mutex every voucher/preimage record() needs; only the fsync runs after release.
Fix: clone (or drain a dirty queue) under the lock, encode outside.
Improves: the flush's lock hold becomes O(dirty) pointer copies instead of O(dirty) serialization.
Leaving as-is limits: every flush tick, proof acceptance across all lanes stalls for the encode, and the stall grows with dirty-lane count — busier nodes pause payments longer, every 5 seconds, and each blocked proof also parks a runtime worker (sync mutex under the async lane lock).
2. Settlement reads clone the whole lane map under the same mutex, on the async runtime
payment_settlement.rs:670,688,1169 (load_all) and :1126 (get) → channel_store.rs:667-675 — the redeemer clones every LaneState under the buffer mutex, directly on an async task rather than spawn_blocking.
Fix: move settlement reads to spawn_blocking; with #1792 item 1, read per-lane instead of whole-map.
Improves: settlement sweeps stop contending with proof commits and stop hogging a worker.
Leaving as-is limits: redemption cadence couples to delivery: each sweep freezes proof acceptance for O(all lanes) clone time, so growing lane counts make routine settlement a recurring node-wide payment stall — and via the credit window, a delivery stall.
3. One lanes.redb writer serializes every durable write family
Lane flush (channel_store.rs:819-848), capability persist (:907-909, the #1789 item-1 TTFB fsync), pending-settle (:1157,:1228), floor-loss (:1290,:1386,:1427), checkpoints (:1537), and the buyer table (buyer_pool_table.rs:242-251) all commit Durability::Immediate on one file — one writer slot. The contention is already called out in comments (channel_store.rs:485-492, mod.rs:485-492).
Fix: split table families into separate DB files, or funnel all writes through one background writer with group commit (the #1483 direction), so no request-path write ever waits on an unrelated commit.
Improves: inline durable writes (capability intake until #1789 lands; floor-loss on abnormal stream end) stop queueing behind the periodic flush and each other.
Leaving as-is limits: durability bursts anywhere (a big flush, a settlement checkpoint, a buyer top-up) back-pressure TTFB and stream teardown through the shared writer — disk-commit serialization becomes a hidden cross-subsystem queue whose depth grows with overall node activity.
4. eviction_candidates iterates the full access_times map under the guard
engine.rs:3133-3152, on the 1 s sweep. Subsumed by #1793 item 1 (sharding); the interim fix is copy-then-filter under a short hold.
Improves: the sweep stops holding the serve path's completion lock for O(cache-size).
Leaving as-is limits: same coupling as #1793 item 1, from the other side — sweep duration grows with cache entry count and is paid by concurrent serve completions.
5. Bounded admin/maintenance scans — keep them from growing
LaneActivityClock::ages locks every lane's mutex sequentially (mod.rs:189, admin readout); probe_holds does O(N) retain sweeps under its mutex (engine.rs:2151,2176-2185, bounded by max_probe_holds, default 256).
Fix: none needed now; treat as guardrails — if max_probe_holds is raised substantially or lane counts explode, these become the next scan-under-lock items.
Improves / leaving as-is: currently bounded and off the request path; the risk is silent growth, so they are listed to keep them on the radar rather than to schedule work.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
perf(node): make open_hardened_db error text family-neutral (#1795 it…
perf(node): split the lane store into per-family redb files (#1795 it…