Skip to content

perf(slirp): port-forward listener on epoll (50 ms → sub-ms accept latency)#77

Merged
dpsoft merged 1 commit intomainfrom
port-forward-listener-epoll-clean
May 6, 2026
Merged

perf(slirp): port-forward listener on epoll (50 ms → sub-ms accept latency)#77
dpsoft merged 1 commit intomainfrom
port-forward-listener-epoll-clean

Conversation

@dpsoft
Copy link
Copy Markdown
Contributor

@dpsoft dpsoft commented May 6, 2026

Summary

Each TCP port-forward rule used to burn one thread polling TcpListener::accept() with 50 ms sleeps between WouldBlock returns. That thread was both the accept-latency floor and the only piece of networking still polling on a fixed cadence after Phase 6.4.

Listener FDs are exactly what EpollDispatch handles. Bind + register the listener under PROTO_TAG_LISTEN at construction time; the net-poll thread sees readiness, accepts the connection (drains WouldBlock), and feeds the existing InboundAccept channel. No dedicated thread per rule.

Drops port_forward_accept_latency from ~50 ms to sub-millisecond — bounded by epoll_wait's active 5 ms cadence rather than a fixed 50 ms poll.

Removes

  • run_port_forward_listener (thread main loop)
  • spawn_port_forward_listeners (now bind_port_forward_listeners)
  • PORT_FORWARD_POLL_INTERVAL
  • port_forward_shutdown Arc<AtomicBool>
  • The Drop impl block that joined listener threads

Replaces #72

This is the single substantive commit (e51e409) that #72 was meant to land, cherry-picked clean onto current main. PR #72 carried 121 stale commits that were squash-merged via PR #69 — closing it in favor of this clean PR.

Test plan

  • cargo fmt --all -- --check — clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — clean
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features — clean
  • cargo test --test network_baseline -- --test-threads=1 — 18/18
  • CI

File changes

  • benches/network.rs — bench harness updated to seed listeners through bind_port_forward_listeners
  • src/network/slirp.rs — listener path moved onto EpollDispatch (+158/-171)

Each TCP port-forward rule used to burn one thread that polled
TcpListener::accept() with 50 ms sleeps between WouldBlock returns.
That thread was both the accept-latency floor and the only piece of
networking still polling on a fixed cadence after Phase 6.4.

Listener FDs are exactly what EpollDispatch handles. Bind +
register the listener under PROTO_TAG_LISTEN at construction time;
the net-poll thread sees readiness, accepts the connection (drains
WouldBlock), and feeds the existing InboundAccept channel. No
dedicated thread per rule.

Drops port_forward_accept_latency from ~50 ms to sub-millisecond
(divan microbench is host TcpStream::connect → first frame in
inject_to_guest, now bounded by epoll_wait latency in the active
5 ms cadence rather than a fixed 50 ms poll).

Removes:
- run_port_forward_listener (thread main loop)
- spawn_port_forward_listeners (now bind_port_forward_listeners)
- PORT_FORWARD_POLL_INTERVAL
- port_forward_shutdown Arc<AtomicBool>
- the Drop impl block that joined listener threads
@dpsoft dpsoft merged commit 67761f6 into main May 6, 2026
22 checks passed
@dpsoft dpsoft deleted the port-forward-listener-epoll-clean branch May 6, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant