Skip to content

Commit 26cb905

Browse files
wan9chiclaude
andcommitted
test(fspy-benchmark): add a contended access row
The thread count was one constant shared by every suite, fixed at two — enough to represent a normal tracked process, but not enough to make writers fight over the channel's counters. Each record costs two atomic read-modify-writes on words every other thread is touching, and two threads barely provoke that. The count moves onto the suite, so the existing rows keep their two threads and their comparability, and a new `access-contended` row runs the same opens under eight. It halves the iterations over half the opens, so four times the threads cost about the same wall clock. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 7968ab4 commit 26cb905

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

crates/fspy_benchmark/src/main.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ const DYNAMIC_TARGET: &str = env!("CARGO_BIN_FILE_FSPY_BENCHMARK_TARGET");
2929
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
3030
const STATIC_TARGET: &str = env!("CARGO_BIN_FILE_FSPY_BENCHMARK_STATIC_TARGET");
3131

32-
/// Threads the target runs, passed through to it. Two, because a process that
33-
/// fspy tracks rarely accesses files from one thread.
34-
const THREADS: &str = "2";
35-
3632
/// What a suite reads out of its launches.
3733
#[derive(Clone, Copy)]
3834
enum Metric {
@@ -44,6 +40,10 @@ enum Metric {
4440

4541
struct Suite {
4642
name: &'static str,
43+
/// Threads the target runs, passed through to it. Two for most suites,
44+
/// because a process that fspy tracks rarely accesses files from one
45+
/// thread.
46+
threads: &'static str,
4747
/// Opens per target thread, passed through to it.
4848
opens: &'static str,
4949
/// Measured iterations. Each one launches every arm once.
@@ -62,6 +62,7 @@ struct Suite {
6262
/// affords fewer of them in the same time.
6363
const LAUNCH_SUITE: Suite = Suite {
6464
name: "launch",
65+
threads: "2",
6566
opens: "0",
6667
iterations: if cfg!(windows) { 150 } else { 300 },
6768
warmup: 5,
@@ -75,6 +76,7 @@ const LAUNCH_SUITE: Suite = Suite {
7576
/// joining on top.
7677
const ACCESS_SUITE: Suite = Suite {
7778
name: "access",
79+
threads: "2",
7880
opens: "2048",
7981
iterations: 102,
8082
warmup: 3,
@@ -84,13 +86,30 @@ const ACCESS_SUITE: Suite = Suite {
8486

8587
const RELATIVE_ACCESS_SUITE: Suite = Suite {
8688
name: "access-relative",
89+
threads: "2",
8790
opens: "2048",
8891
iterations: 102,
8992
warmup: 3,
9093
metric: Metric::Typical,
9194
relative: true,
9295
};
9396

97+
/// The same opens under enough threads to make them fight over the tracker's
98+
/// shared counters. Each record costs two atomic read-modify-writes on words
99+
/// every other thread is also touching, so this is the row that prices how
100+
/// that contention scales; the two-thread rows barely provoke it. Runs half
101+
/// the iterations of the plain suite over half the opens, so four times the
102+
/// threads cost about the same wall clock.
103+
const CONTENDED_ACCESS_SUITE: Suite = Suite {
104+
name: "access-contended",
105+
threads: "8",
106+
opens: "1024",
107+
iterations: 54,
108+
warmup: 3,
109+
metric: Metric::Typical,
110+
relative: false,
111+
};
112+
94113
struct Backend {
95114
name: &'static str,
96115
target: &'static str,
@@ -114,7 +133,8 @@ fn main() {
114133
validate(base_launcher, backend.target, relative);
115134
}
116135
}
117-
for suite in [&LAUNCH_SUITE, &ACCESS_SUITE, &RELATIVE_ACCESS_SUITE] {
136+
for suite in [&LAUNCH_SUITE, &ACCESS_SUITE, &RELATIVE_ACCESS_SUITE, &CONTENDED_ACCESS_SUITE]
137+
{
118138
run_suite(backend, suite, base_launcher.as_deref());
119139
}
120140
}
@@ -237,7 +257,7 @@ fn launch(launcher: &OsStr, mode: Option<&str>, backend: &Backend, suite: &Suite
237257
command.arg("--relative");
238258
}
239259
let output = command
240-
.args([backend.target, THREADS, suite.opens])
260+
.args([backend.target, suite.threads, suite.opens])
241261
.stdin(Stdio::null())
242262
.stderr(Stdio::inherit())
243263
.output()

0 commit comments

Comments
 (0)