Skip to content

perf(node): background tasks steal hot-path locks — flush/settlement under LaneBuffer, single redb writer, sweep scans #1795

Closed

Description

@alpergundogdu

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.

Related: #1787–#1794.

Activity

  1. moved this from Backlog to Ready in deCDNon Aug 24, 2026
  2. added
    rust
    prio:low
    on Aug 26, 2026
  3. moved this from Ready to In progress in deCDNon Aug 31, 2026
  4. moved this from In progress 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:lowrust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions