Skip to content

bench: profile Arc<Mutex<Vec>> contention in parallel-stat path (#1192) - #4170

Merged
oferchen merged 2 commits into
masterfrom
bench/arc-mutex-parallel-stat-1192
May 16, 2026
Merged

oferchen merged 2 commits into
masterfrom
bench/arc-mutex-parallel-stat-1192

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add criterion microbench (crates/transfer/benches/parallel_stat_collector_contention.rs) profiling four result-collection strategies (shared Arc<Mutex<Vec>>, sharded Mutex<Vec> by rayon worker id, crossbeam_queue::SegQueue, crossbeam_channel::unbounded) at 100K items across 1/4/8/16 rayon workers. Throughput is reported in elements/sec via BenchmarkGroup::throughput(Throughput::Elements), so the report directly names the worker count at which the single shared mutex saturates.
  • Document that the shipping parallel-stat path (crates/transfer/src/parallel_io.rs::map_blocking) does not use Arc<Mutex<Vec>> today; it collects via into_par_iter().map(f).collect(), which delegates to rayon's lock-free reducer. New audit at docs/audits/parallel-stat-collection.md inventories every parallel-stat call site, lists the two production Mutex<Vec> sites that exist (both off the parallel-stat path), and explains why the rayon reducer wins by default.
  • Add crossbeam-channel as a dev-dependency for the transfer crate (already a workspace dep used by engine).

Why

Tracking issue #1192 asked whether the receiver's parallel-stat result collector is an Arc<Mutex<Vec>> bottleneck under 100K+ files on 8+ core hosts. Static audit shows it is not; the bench produces the numerical evidence needed to reject any future PR that proposes reintroducing the pattern (related: #1271, #1297, #1370, #1682). The microbench does not change runtime behaviour.

Test plan

  • CI green on all required matrices (fmt+clippy, nextest stable, Windows stable, macOS stable, Linux musl stable).
  • cargo bench -p transfer -- parallel_stat_collector_contention runs to completion locally for at least one reviewer.
  • Bench output confirms the expected curve: arc_mutex_vec flattens or regresses past T=4-8 while sharded_mutex_vec and the lock-free queues continue scaling.

oferchen added 2 commits May 16, 2026 23:15
Add criterion microbench under crates/transfer/benches profiling four
result-collection strategies (shared Arc<Mutex<Vec>>, sharded
Mutex<Vec> by rayon worker id, crossbeam SegQueue, crossbeam unbounded
channel) over 100K items at 1/4/8/16 rayon worker counts. Throughput
is reported in elements/sec so the bench output names the worker
count at which the single shared mutex saturates.

The shipping parallel-stat path in crates/transfer/src/parallel_io.rs
does not use Arc<Mutex<Vec>>; it collects via
into_par_iter().map(f).collect(), which delegates to rayon's lock-free
reducer. Document this in docs/audits/parallel-stat-collection.md and
keep the microbench as the baseline against which any future PR that
proposes reintroducing a shared mutex on this path must be measured
(tracked under #1192, #1271, #1297, #1370, #1682).
@oferchen
oferchen force-pushed the bench/arc-mutex-parallel-stat-1192 branch from 46a89d9 to dac4244 Compare May 16, 2026 20:15
@oferchen
oferchen merged commit c8d0b24 into master May 16, 2026
19 of 20 checks passed
@oferchen
oferchen deleted the bench/arc-mutex-parallel-stat-1192 branch May 16, 2026 20:20
oferchen added a commit that referenced this pull request May 17, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request May 17, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 17, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 17, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 18, 2026
… (#4170)

* chore(bench): add parallel-stat collector contention microbench

Add criterion microbench under crates/transfer/benches profiling four
result-collection strategies (shared Arc<Mutex<Vec>>, sharded
Mutex<Vec> by rayon worker id, crossbeam SegQueue, crossbeam unbounded
channel) over 100K items at 1/4/8/16 rayon worker counts. Throughput
is reported in elements/sec so the bench output names the worker
count at which the single shared mutex saturates.

The shipping parallel-stat path in crates/transfer/src/parallel_io.rs
does not use Arc<Mutex<Vec>>; it collects via
into_par_iter().map(f).collect(), which delegates to rayon's lock-free
reducer. Document this in docs/audits/parallel-stat-collection.md and
keep the microbench as the baseline against which any future PR that
proposes reintroducing a shared mutex on this path must be measured
(tracked under #1192, #1271, #1297, #1370, #1682).

* chore: sync Cargo.lock after dev-dep addition
oferchen added a commit that referenced this pull request May 18, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request May 18, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request May 18, 2026
… (#4170)

* chore(bench): add parallel-stat collector contention microbench

Add criterion microbench under crates/transfer/benches profiling four
result-collection strategies (shared Arc<Mutex<Vec>>, sharded
Mutex<Vec> by rayon worker id, crossbeam SegQueue, crossbeam unbounded
channel) over 100K items at 1/4/8/16 rayon worker counts. Throughput
is reported in elements/sec so the bench output names the worker
count at which the single shared mutex saturates.

The shipping parallel-stat path in crates/transfer/src/parallel_io.rs
does not use Arc<Mutex<Vec>>; it collects via
into_par_iter().map(f).collect(), which delegates to rayon's lock-free
reducer. Document this in docs/audits/parallel-stat-collection.md and
keep the microbench as the baseline against which any future PR that
proposes reintroducing a shared mutex on this path must be measured
(tracked under #1192, #1271, #1297, #1370, #1682).

* chore: sync Cargo.lock after dev-dep addition
oferchen added a commit that referenced this pull request May 18, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request May 18, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
oferchen added a commit that referenced this pull request Aug 24, 2026
… (#4170)

* chore(bench): add parallel-stat collector contention microbench

Add criterion microbench under crates/transfer/benches profiling four
result-collection strategies (shared Arc<Mutex<Vec>>, sharded
Mutex<Vec> by rayon worker id, crossbeam SegQueue, crossbeam unbounded
channel) over 100K items at 1/4/8/16 rayon worker counts. Throughput
is reported in elements/sec so the bench output names the worker
count at which the single shared mutex saturates.

The shipping parallel-stat path in crates/transfer/src/parallel_io.rs
does not use Arc<Mutex<Vec>>; it collects via
into_par_iter().map(f).collect(), which delegates to rayon's lock-free
reducer. Document this in docs/audits/parallel-stat-collection.md and
keep the microbench as the baseline against which any future PR that
proposes reintroducing a shared mutex on this path must be measured
(tracked under #1192, #1271, #1297, #1370, #1682).

* chore: sync Cargo.lock after dev-dep addition
oferchen added a commit that referenced this pull request Aug 24, 2026
Design note for the lock-free MPSC variant of
WorkQueueReceiver::drain_parallel. Sketches the crossbeam_channel
swap, documents the ordering contract delegated to ReorderBuffer,
defines the 20% threshold on the #4214 drain_parallel_alternatives
bench that gates the migration, and lays out a feature-flag rollout
plan. Recommendation is to defer the implementation until the
#4214 numbers land on the reference host. Cross-refs #4170, #4173,
#4203, #4214.
oferchen added a commit that referenced this pull request Aug 24, 2026
Adds drain_parallel_alternatives benchmark comparing three fan-in
strategies on the WorkQueueReceiver drain path: the current sharded
Mutex<Vec> indexed by rayon thread index, a per-thread Vec with final
concat (no mutex), and a crossbeam_channel MPSC drain. Runs at 10K and
100K items across 4, 8, and 16 rayon workers, reporting throughput in
elements per second so reviewers can compare per-iteration cost
directly.

Pre-allocates DeltaWork items outside the timed section, isolates each
worker count in a private rayon pool, and shares the same simulated
per-item compute across strategies so the only delta between groups is
the collector itself. Closes the measurement gap that #1681 needs to
decide whether the current sharded Mutex<Vec> warrants replacement
(#1682, refs #4170 / #4173 / #4203).
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