Skip to content

perf(node): accept path — per-connection head-of-line blocking and admission stalls on cdn/client/v1 #1788

Closed

Description

@alpergundogdu

Group A of the serve-path hot-path audit (doc-drift finding: #1787). One issue per path so the group can be fixed together; items are ranked by impact within this path.

All items below sit on the connection accept / stream admission path shared by every stream on a cdn/client/v1 connection.

1. Streams run as FuturesUnordered on the single accept task

crates/node/src/handlers/client/dispatch.rs:55-63 (rationale comment at :18-23: the iroh ProtocolHandler::accept &self borrow). Every synchronous CPU cost on the stream path — the two ecrecovers and the response ECDSA sign at open, the per-voucher ecrecover, the up-to-255-keccak preimage walk, the per-frame memcpys — executes on the one task that also runs conn.accept_bi() and every sibling stream.

Fix: tokio::spawn per stream (hold handler state via Arc to satisfy 'static), or at minimum push all secp256k1 work onto a worker pool.

Improves: converts every synchronous cost on this path from a connection-wide stall into a single-stream cost; the accept loop stays responsive; sibling streams stop inheriting each other's latency. This one change re-rates most items in the sibling issues.

Leaving as-is limits: p99 TTFB and mid-stream jitter grow linearly with concurrent streams per connection (up to 100 per ADR 005 §Concurrent stream limits). One voucher-heavy stream stalls all siblings and delays acceptance of new streams. Effective per-connection throughput is bounded by one core's worth of serialized CPU, which is exactly the bulk-fetch case (video manifest + segments) the 100-stream limit exists to serve.

2. Per-source keyspace prune runs inline on the accept path

crates/node/src/dispatch.rs:458-471 — the single-flighted retain_recent() O(n) walk over the per-source limiter keyspace runs inline on the accept that trips the cap + cap/10 threshold.

Fix: move the prune to a background timer; accepts only ever do the bucket check.

Improves: constant-time connection admission.

Leaving as-is limits: with many distinct source IPs (public scale-up, connection churn, probe-heavy peers) the O(n) walk lands on an arbitrary victim's connection setup, and the spike grows with keyspace size — connection-establishment latency becomes load-dependent.

3. bound_addr is a tokio::Mutex taken twice per request

crates/node/src/handlers/client/dispatch.rs:51,141,152 — the connection-cached verified client binding is write-once-then-read but lives behind an async mutex, adding two await points per StreamRequest.

Fix: ArcSwapOption<Address> (or OnceLock-style cell).

Improves: removes two scheduling points from every request on the connection.

Leaving as-is limits: small fixed per-request overhead plus cooperative-yield opportunities on the shared accept task (amplified by item 1); pure noise at scale that is cheap to delete.

4. ConnectionLimiter.per_source is the last RwLock on the accept read path

crates/node/src/dispatch.rs:240 (read at :433,504,532; reload write at :307-311). Every other reload-fed structure on the serve path is ArcSwap/atomic.

Fix: ArcSwap<PerSource>; reads already clone the limiter Arc out.

Improves: fully lock-free admission reads, consistent with the rest of the reload surface.

Leaving as-is limits: microsecond-scale reader stalls during config reload only — minor, but it is the last lock of its kind on this path and removing it closes the class.

Related: #1787. Sibling issues cover TTFB open path, miss/fill, delivery loop, voucher path, stream-end, pull leg, and background contention.

Activity

  1. moved this from Backlog to Ready in deCDNon Aug 24, 2026
  2. added
    rust
    prio:high
    on Aug 26, 2026
  3. moved this from Ready to In progress in deCDNon Aug 29, 2026
  4. moved this from In progress to Done in deCDNon Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:highrust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions