Skip to content

bench(daemon): thread-per-connection scaling at 100/1k/10k connections (#1933) - #4182

Merged
oferchen merged 4 commits into
masterfrom
bench/daemon-thread-per-connection-1933
May 16, 2026
Merged

oferchen merged 4 commits into
masterfrom
bench/daemon-thread-per-connection-1933

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds crates/daemon/tests/connection_scaling_stress.rs, a stress harness that drives 100 / 1000 / 10000 concurrent TCP clients against the daemon's std::thread::spawn-per-connection listener.
  • Measures wall time, per-connection latency, ECONNREFUSED / EMFILE / generic failure counts, and peak RSS via getrusage(RUSAGE_SELF).ru_maxrss.
  • All three scenarios are gated with #[ignore] so the default nextest run is unaffected. The 10000-connection case is #[cfg(unix)] and tries to raise RLIMIT_NOFILE to the hard limit; when the hard limit is too low it self-skips with a logged message instead of failing.

Why

Issue #1933 asks for quantitative evidence about whether the current thread-per-connection model is a bottleneck before committing to an async listener (tracked separately as #1935 / #1367). This harness produces the numbers needed for that decision without changing the daemon itself.

Running the harness

cargo nextest run -p daemon --test connection_scaling_stress --run-ignored only -- --test-threads=1
# or with the default harness:
cargo test  -p daemon --test connection_scaling_stress --      --ignored --test-threads=1

Each scenario prints a one-line report like:

[daemon-stress] 1k_conn: target=1000 ok=1000 refused=0 emfile=0 other=0 wall=523.7 ms (523.7 us/conn) peak_rss=42.31 MiB

Test plan

  • CI fmt+clippy on Linux, macOS, Windows (ignored tests still compile on all platforms).
  • CI nextest stable: ignored tests stay skipped, suite passes unchanged.
  • Manual run of all three ignored cases on Linux to capture baseline scaling numbers (deferred; this PR ships the harness only).

@oferchen
oferchen force-pushed the bench/daemon-thread-per-connection-1933 branch 4 times, most recently from 9ab3c74 to 6db0546 Compare May 16, 2026 22:08
oferchen added 4 commits May 17, 2026 01:34
Adds an integration-test-shaped stress benchmark that drives 100, 1000,
and 10000 concurrent TCP clients against the daemon listener, capturing
wall time, ECONNREFUSED / EMFILE counts, and peak RSS via getrusage. All
three scenarios are marked #[ignore]; the 10k case is unix-only and
self-skips when RLIMIT_NOFILE cannot accommodate the request.

The harness exists to provide evidence for whether an async listener
(tracked separately) would be a meaningful change to the current
std::thread::spawn-per-connection model.
The conversion was redundant on all targets we build on: c_long is i64
on 64-bit Linux/macOS (no conversion needed) and i32 on 32-bit Linux
(the subsequent 'as u64' sign-extends to i64 first, then saturating_mul
operates on u64). Removing the conversion silences both
clippy::unnecessary_cast and clippy::useless_conversion without losing
overflow safety.
@oferchen
oferchen force-pushed the bench/daemon-thread-per-connection-1933 branch from 6db0546 to 7c7fd9d Compare May 16, 2026 22:34
@oferchen
oferchen merged commit 11ec9ed into master May 16, 2026
12 checks passed
@oferchen
oferchen deleted the bench/daemon-thread-per-connection-1933 branch May 16, 2026 22:34
oferchen added a commit that referenced this pull request May 18, 2026
#1933) (#4182)

* chore(bench): stress harness for thread-per-connection scaling

Adds an integration-test-shaped stress benchmark that drives 100, 1000,
and 10000 concurrent TCP clients against the daemon listener, capturing
wall time, ECONNREFUSED / EMFILE counts, and peak RSS via getrusage. All
three scenarios are marked #[ignore]; the 10k case is unix-only and
self-skips when RLIMIT_NOFILE cannot accommodate the request.

The harness exists to provide evidence for whether an async listener
(tracked separately) would be a meaningful change to the current
std::thread::spawn-per-connection model.

* style(daemon): apply rustfmt to connection_scaling_stress

* fix(daemon): convert ru_maxrss via i64::from for cross-arch portability

* fix(daemon): use ru_maxrss directly without conversion

The conversion was redundant on all targets we build on: c_long is i64
on 64-bit Linux/macOS (no conversion needed) and i32 on 32-bit Linux
(the subsequent 'as u64' sign-extends to i64 first, then saturating_mul
operates on u64). Removing the conversion silences both
clippy::unnecessary_cast and clippy::useless_conversion without losing
overflow safety.
oferchen added a commit that referenced this pull request May 18, 2026
#1933) (#4182)

* chore(bench): stress harness for thread-per-connection scaling

Adds an integration-test-shaped stress benchmark that drives 100, 1000,
and 10000 concurrent TCP clients against the daemon listener, capturing
wall time, ECONNREFUSED / EMFILE counts, and peak RSS via getrusage. All
three scenarios are marked #[ignore]; the 10k case is unix-only and
self-skips when RLIMIT_NOFILE cannot accommodate the request.

The harness exists to provide evidence for whether an async listener
(tracked separately) would be a meaningful change to the current
std::thread::spawn-per-connection model.

* style(daemon): apply rustfmt to connection_scaling_stress

* fix(daemon): convert ru_maxrss via i64::from for cross-arch portability

* fix(daemon): use ru_maxrss directly without conversion

The conversion was redundant on all targets we build on: c_long is i64
on 64-bit Linux/macOS (no conversion needed) and i32 on 32-bit Linux
(the subsequent 'as u64' sign-extends to i64 first, then saturating_mul
operates on u64). Removing the conversion silences both
clippy::unnecessary_cast and clippy::useless_conversion without losing
overflow safety.
oferchen added a commit that referenced this pull request Aug 24, 2026
#1933) (#4182)

* chore(bench): stress harness for thread-per-connection scaling

Adds an integration-test-shaped stress benchmark that drives 100, 1000,
and 10000 concurrent TCP clients against the daemon listener, capturing
wall time, ECONNREFUSED / EMFILE counts, and peak RSS via getrusage. All
three scenarios are marked #[ignore]; the 10k case is unix-only and
self-skips when RLIMIT_NOFILE cannot accommodate the request.

The harness exists to provide evidence for whether an async listener
(tracked separately) would be a meaningful change to the current
std::thread::spawn-per-connection model.

* style(daemon): apply rustfmt to connection_scaling_stress

* fix(daemon): convert ru_maxrss via i64::from for cross-arch portability

* fix(daemon): use ru_maxrss directly without conversion

The conversion was redundant on all targets we build on: c_long is i64
on 64-bit Linux/macOS (no conversion needed) and i32 on 32-bit Linux
(the subsequent 'as u64' sign-extends to i64 first, then saturating_mul
operates on u64). Removing the conversion silences both
clippy::unnecessary_cast and clippy::useless_conversion without losing
overflow safety.
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