Skip to content

perf(transfer): enable parallel receive-delta by default via Path B heuristic (PIP-3 + PIP-5) - #4666

Merged
oferchen merged 3 commits into
masterfrom
perf/transfer-parallel-receive-default-on-pip3-pip5
May 21, 2026
Merged

oferchen merged 3 commits into
masterfrom
perf/transfer-parallel-receive-default-on-pip3-pip5

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Wires the receiver-side parallel delta apply path into production per
docs/design/parallel-receive-delta-default-on.md Path B (sections 6.2
and 8), combining steps 4 and 5 in a single PR. Unblocks PIP-3 (#2566)
and PIP-5 (#2568).

The receiver now picks sequential vs parallel apply per transfer using a
cheap, no-cost heuristic:

  • file_count > 100 (next common cutoff above the rayon
    PARALLEL_STAT_THRESHOLD = 64 convention in MEMORY.md)
  • or total_size > 64 MiB (the copy_file_range crossover
    documented in crates/engine/benches/per_op_thresholds.rs)

The dispatch decision is recorded on TransferStats::receiver_strategy_chosen
(ReceiverStrategy::{Sequential, Parallel}) for telemetry and logged
under --debug=GENR:

[generator] receiver_strategy=parallel file_count=N total_size=M (threshold: file_count>100 || total_size>67108864)

What changed

  • New thresholds + helpers on ReceiverContext:
    PARALLEL_RECEIVE_FILE_COUNT_THRESHOLD,
    PARALLEL_RECEIVE_BYTES_THRESHOLD,
    select_receiver_strategy(), total_source_bytes(),
    dispatch_receiver_strategy() in
    crates/transfer/src/receiver/mod.rs.
  • Dispatch invoked at the top of run_sync, run_pipelined, and
    run_pipelined_incremental, immediately after setup_transfer
    returns the file count and the file list is in memory.
  • New ReceiverStrategy enum on TransferStats::receiver_strategy_chosen
    in crates/transfer/src/receiver/stats.rs.
  • parallel-receive-delta added to default = [...] on engine,
    transfer, core, cli, and the workspace binary. Sequential is
    the fallback when the heuristic returns false and when the
    feature is compiled out (receiver_strategy=parallel_unavailable
    log + sequential return so telemetry never lies).
  • Docs: docs/design/parallel-receive-delta-default-on.md sections 1,
    5, and 8 updated. Steps 4 and 5 marked SHIPPED. Section 5 notes the
    maintainer directive bypassing the soak / bench gates.

Risk acceptance (per maintainer directive 2026-05-21)

Follow-ups

  • PIP-4: re-run the interop suite through the parallel apply path.
  • PIP-6: backfill the section-4 bench table from the
    parallel_receive_delta_perf harness.
  • Track sections 5.1, 5.3, 5.4, 5.5 promotion criteria as continuous
    follow-up rather than blocking gates.

Test plan

Refs #1368, #2566, #2568.

…euristic

Wires the receiver-side parallel delta apply path into production per
`docs/design/parallel-receive-delta-default-on.md` Path B, combining
steps 4 and 5 in a single change.

- Add `PARALLEL_RECEIVE_FILE_COUNT_THRESHOLD = 100` and
  `PARALLEL_RECEIVE_BYTES_THRESHOLD = 64 MiB` on the receiver. Thresholds
  match the existing rayon parallel-stat cutoff convention and the
  `copy_file_range` 64 MiB crossover.
- Add `ReceiverContext::select_receiver_strategy(file_count, total_size)`
  (pure heuristic), `total_source_bytes()` (sums the in-memory file
  list), and `dispatch_receiver_strategy()` (logs the decision under the
  `GENR` debug channel and swaps the delta pipeline when the
  `parallel-receive-delta` feature is on).
- Call `dispatch_receiver_strategy` at the top of `run_sync`,
  `run_pipelined`, and `run_pipelined_incremental`, immediately after
  `setup_transfer` returns the file count and the file list is in
  memory.
- Surface the choice as `TransferStats::receiver_strategy_chosen` via
  the new `ReceiverStrategy { Sequential, Parallel }` enum
  (`Sequential` by default).
- Promote `parallel-receive-delta` into the `default = [...]` set on
  `engine`, `transfer`, `core`, `cli`, and the workspace binary so the
  shipped `oc-rsync` picks up the dispatch with no opt-in flag. Stay
  compatible with `--no-default-features` builds: when the feature is
  compiled out the dispatcher logs `receiver_strategy=parallel_unavailable`
  and falls back to sequential so the telemetry counter never lies
  about the path actually taken.

Tests:
- Unit coverage for the heuristic boundary matrix (below/above each
  threshold, exact-boundary, empty transfer).
- File-list-integration coverage for `total_source_bytes` and the full
  `dispatch_receiver_strategy` flow with populated file lists.

Wire-format parity stays guarded by the existing proptests (#4300 +
#4319). The soak + bench gates (criteria 1, 3, 4, 5 in section 5) are
explicit risk acceptance; PIP-4 (interop suite re-run) and PIP-6 (bench
backfill) remain as follow-ups.

Refs #1368, #2566, #2568.
oferchen added 2 commits May 21, 2026 13:28
CI fmt+clippy diff: collapsed select_receiver_strategy multi-line
signature and the FileEntry::new_file argument list in
dispatch_large_bytes_picks_parallel onto single lines.

Behaviour-neutral.
clippy::identity-op fired on `1 * 1024 * 1024`. Collapsed to
`1024 * 1024` in the two boundary-matrix tests.
@oferchen
oferchen merged commit 2b4cb55 into master May 21, 2026
64 checks passed
@oferchen
oferchen deleted the perf/transfer-parallel-receive-default-on-pip3-pip5 branch May 21, 2026 12:24
oferchen added a commit that referenced this pull request May 21, 2026
Discharges the ABW-1 audit's recommendation (PR #4670, section 4) to
skip the pipelined verify/write design for apply_batch_parallel until
bench evidence shows verify and write costs within 2x of each other on
a production-relevant workload cell.

- Recaps the ABW-1 quantified speedup table (1.13x balanced, 1.50x
  CPU-bound, 1.03x I/O-bound, ~0x single-file).
- Documents why deferring the design (not just the implementation) is
  the right call: peak benefit is workload-dependent, complexity-to-
  payoff is poor in the measured cells, and the PIP-3+5 dispatch
  heuristic (PR #4666) already gates the degenerate single-file case
  out of parallel-receive-delta.
- Names BR-3j.f (#2508) as the gating re-bench task and lifts the
  audit's decision gate verbatim.
- Preserves the option: per-file Mutex is the real bottleneck; a
  future multi-threaded-per-file writer or a CPU-bound verify regime
  would re-open ABW-2.
oferchen added a commit that referenced this pull request May 21, 2026
…PIP-3+5 wire-up (#4677)

Combined closure note covering three trackers whose deliverables have
already shipped or were absorbed into existing design surface:

- PIP-2 (#2565): the design doc was supposed to describe the
  token_loop -> ParallelDeltaApplier migration. That document already
  exists as docs/design/parallel-receive-delta-default-on.md
  (shipped in PR #4319 scaffold, extended by PR #4666 default-on
  flip). Marked completed retroactively.
- FFB-3 (#2576): conditional task that only activated if FFB-1 chose
  Option A or B. FFB-1 (PR #4659) chose Option D - barrier baked into
  finish_file - so every existing caller already gets the barrier
  without callsite migration. Marked deferred N-A.
- FFB-4 (#2577): explicit flush_workers call at the PIP-3 wire-up
  site. PIP-3 + PIP-5 (PR #4666 merged) routes through finish_file,
  which already barriers via Option D. No explicit call needed.
  Marked satisfied-by-design.

Note: FFB-2 implementation (PR #4665, in CI) needed a spin-then-yield
fix around finish_file's try_unwrap to close a Windows release-race;
future work to restructure DecrementGuard would be FFB-5+ if filed.

No source changes.
oferchen added a commit that referenced this pull request May 21, 2026
Adds the end-to-end production-path bench harness for the parallel-
receive-delta promotion chain. PIP-6 is the third bench in the
sequence after BR-3i.f (#2502, apply-loop) and BR-3j.f (#2508,
post-DashMap re-bench).

Scope: drives a real oc-rsync client against a real oc-rsync daemon
over rsync:// loopback, on workload shapes calibrated to the Path B
dispatch boundary (file_count > 100 || total_size > 64 MiB) that
PIP-3+5 (PR #4666) wired into ReceiverContext::dispatch_receiver_strategy.

Comparison shape: same workload, two oc-rsync binaries (default-features
build vs --no-default-features --features 'zstd lz4 xattr iconv').
The no-parallel build trips the parallel_unavailable fallback path
in crates/transfer/src/receiver/mod.rs and always picks sequential.

Workload matrix:
- single_large_file (1x1 GiB, parallel by byte threshold)
- many_small_files (10_000x4 KiB, parallel by count)
- boundary_under (50 files, 32 MiB, sequential control)
- boundary_over (200 files, 32 MiB, parallel above count)
- mixed_directory (1_000 files, ~600 MiB, parallel)

Decision criteria:
- Win on >= 2 of 5 shapes (parallel_wall / sequential_wall <= 0.9)
- No shape regresses by more than 5%
- boundary_under within +/-3% (harness control)

Bench compiles; numbers capture is the follow-up. The section-4 table
in docs/design/parallel-receive-delta-default-on.md is the target for
the wall-clock data.
oferchen added a commit that referenced this pull request May 21, 2026
…#4679)

Adds the end-to-end production-path bench harness for the parallel-
receive-delta promotion chain. PIP-6 is the third bench in the
sequence after BR-3i.f (#2502, apply-loop) and BR-3j.f (#2508,
post-DashMap re-bench).

Scope: drives a real oc-rsync client against a real oc-rsync daemon
over rsync:// loopback, on workload shapes calibrated to the Path B
dispatch boundary (file_count > 100 || total_size > 64 MiB) that
PIP-3+5 (PR #4666) wired into ReceiverContext::dispatch_receiver_strategy.

Comparison shape: same workload, two oc-rsync binaries (default-features
build vs --no-default-features --features 'zstd lz4 xattr iconv').
The no-parallel build trips the parallel_unavailable fallback path
in crates/transfer/src/receiver/mod.rs and always picks sequential.

Workload matrix:
- single_large_file (1x1 GiB, parallel by byte threshold)
- many_small_files (10_000x4 KiB, parallel by count)
- boundary_under (50 files, 32 MiB, sequential control)
- boundary_over (200 files, 32 MiB, parallel above count)
- mixed_directory (1_000 files, ~600 MiB, parallel)

Decision criteria:
- Win on >= 2 of 5 shapes (parallel_wall / sequential_wall <= 0.9)
- No shape regresses by more than 5%
- boundary_under within +/-3% (harness control)

Bench compiles; numbers capture is the follow-up. The section-4 table
in docs/design/parallel-receive-delta-default-on.md is the target for
the wall-clock data.
oferchen added a commit that referenced this pull request May 22, 2026
… receiver corruption) (#4725)

PIP-4 (#4720) added the `parallel-threshold-trip` interop scenario that
crosses `PARALLEL_RECEIVE_FILE_COUNT_THRESHOLD = 100` and exposed a real
corruption bug: the receiver writes wrong bytes for the first dispatched
file (`parallel_threshold/file_1.txt`) whenever a transfer trips the
parallel-receive-delta dispatch path. The bug reproduces on stock
`cargo build --release` because PIP-5 (#4666) flipped the feature into
the default set across the workspace.

This PR ships the immediate mitigation so default builds are safe again
while PIP-7 investigates the receiver-side corruption:

1. Remove `parallel-receive-delta` from `default = [...]` in the
   workspace `Cargo.toml`, `crates/transfer/Cargo.toml`, and
   `crates/engine/Cargo.toml`. The feature stays defined and remains
   opt-in via `--features parallel-receive-delta` for testing.
2. Remove the `parallel-threshold-trip` matrix entry from
   `tools/ci/run_interop.sh` along with its setup, cleanup, and verify
   branches. The threshold constants in `receiver/mod.rs` stay in place.
3. Add `docs/design/pip-7-parallel-receive-delta-receiver-corruption-2026-05-22.md`
   tracking the open investigation, suspected locations
   (`crates/engine/src/concurrent_delta/parallel_apply.rs` and
   `crates/transfer/src/delta_pipeline/parallel.rs`), reproduction
   recipe, and acceptance criteria for re-promotion.
4. Flag the deferred-pending-PIP-7 status in `README.md`,
   `CHANGELOG.md`, `docs/design/parallel-receive-delta-default-on.md`,
   `docs/design/pip-4-closure-2026-05-21.md`, and
   `docs/design/br-6-sign-off-check-in-2026-05-21.md` so the shipped
   claims no longer read as if default builds exercise the parallel
   receive-delta path.

The `ParallelDeltaApplier`, `dispatch_receiver_strategy()`,
`enable_parallel_receive_delta()`, and the `OC_RSYNC_FORCE_PARALLEL`
debug env knob from PIP-4 are intentionally retained; they remain
reachable when the feature is opted into so the PIP-7 investigation can
iterate against them.
oferchen added a commit that referenced this pull request Aug 24, 2026
…euristic (PIP-3 + PIP-5) (#4666)

* perf(transfer): enable parallel receive-delta by default via Path B heuristic

Wires the receiver-side parallel delta apply path into production per
`docs/design/parallel-receive-delta-default-on.md` Path B, combining
steps 4 and 5 in a single change.

- Add `PARALLEL_RECEIVE_FILE_COUNT_THRESHOLD = 100` and
  `PARALLEL_RECEIVE_BYTES_THRESHOLD = 64 MiB` on the receiver. Thresholds
  match the existing rayon parallel-stat cutoff convention and the
  `copy_file_range` 64 MiB crossover.
- Add `ReceiverContext::select_receiver_strategy(file_count, total_size)`
  (pure heuristic), `total_source_bytes()` (sums the in-memory file
  list), and `dispatch_receiver_strategy()` (logs the decision under the
  `GENR` debug channel and swaps the delta pipeline when the
  `parallel-receive-delta` feature is on).
- Call `dispatch_receiver_strategy` at the top of `run_sync`,
  `run_pipelined`, and `run_pipelined_incremental`, immediately after
  `setup_transfer` returns the file count and the file list is in
  memory.
- Surface the choice as `TransferStats::receiver_strategy_chosen` via
  the new `ReceiverStrategy { Sequential, Parallel }` enum
  (`Sequential` by default).
- Promote `parallel-receive-delta` into the `default = [...]` set on
  `engine`, `transfer`, `core`, `cli`, and the workspace binary so the
  shipped `oc-rsync` picks up the dispatch with no opt-in flag. Stay
  compatible with `--no-default-features` builds: when the feature is
  compiled out the dispatcher logs `receiver_strategy=parallel_unavailable`
  and falls back to sequential so the telemetry counter never lies
  about the path actually taken.

Tests:
- Unit coverage for the heuristic boundary matrix (below/above each
  threshold, exact-boundary, empty transfer).
- File-list-integration coverage for `total_source_bytes` and the full
  `dispatch_receiver_strategy` flow with populated file lists.

Wire-format parity stays guarded by the existing proptests (#4300 +
#4319). The soak + bench gates (criteria 1, 3, 4, 5 in section 5) are
explicit risk acceptance; PIP-4 (interop suite re-run) and PIP-6 (bench
backfill) remain as follow-ups.

Refs #1368, #2566, #2568.

* style(transfer): apply rustfmt to PIP-3+5 receiver-strategy code

CI fmt+clippy diff: collapsed select_receiver_strategy multi-line
signature and the FileEntry::new_file argument list in
dispatch_large_bytes_picks_parallel onto single lines.

Behaviour-neutral.

* fix(transfer): drop identity-op multiplier in receiver-strategy tests

clippy::identity-op fired on `1 * 1024 * 1024`. Collapsed to
`1024 * 1024` in the two boundary-matrix tests.
oferchen added a commit that referenced this pull request Aug 24, 2026
Discharges the ABW-1 audit's recommendation (PR #4670, section 4) to
skip the pipelined verify/write design for apply_batch_parallel until
bench evidence shows verify and write costs within 2x of each other on
a production-relevant workload cell.

- Recaps the ABW-1 quantified speedup table (1.13x balanced, 1.50x
  CPU-bound, 1.03x I/O-bound, ~0x single-file).
- Documents why deferring the design (not just the implementation) is
  the right call: peak benefit is workload-dependent, complexity-to-
  payoff is poor in the measured cells, and the PIP-3+5 dispatch
  heuristic (PR #4666) already gates the degenerate single-file case
  out of parallel-receive-delta.
- Names BR-3j.f (#2508) as the gating re-bench task and lifts the
  audit's decision gate verbatim.
- Preserves the option: per-file Mutex is the real bottleneck; a
  future multi-threaded-per-file writer or a CPU-bound verify regime
  would re-open ABW-2.
oferchen added a commit that referenced this pull request Aug 24, 2026
…PIP-3+5 wire-up (#4677)

Combined closure note covering three trackers whose deliverables have
already shipped or were absorbed into existing design surface:

- PIP-2 (#2565): the design doc was supposed to describe the
  token_loop -> ParallelDeltaApplier migration. That document already
  exists as docs/design/parallel-receive-delta-default-on.md
  (shipped in PR #4319 scaffold, extended by PR #4666 default-on
  flip). Marked completed retroactively.
- FFB-3 (#2576): conditional task that only activated if FFB-1 chose
  Option A or B. FFB-1 (PR #4659) chose Option D - barrier baked into
  finish_file - so every existing caller already gets the barrier
  without callsite migration. Marked deferred N-A.
- FFB-4 (#2577): explicit flush_workers call at the PIP-3 wire-up
  site. PIP-3 + PIP-5 (PR #4666 merged) routes through finish_file,
  which already barriers via Option D. No explicit call needed.
  Marked satisfied-by-design.

Note: FFB-2 implementation (PR #4665, in CI) needed a spin-then-yield
fix around finish_file's try_unwrap to close a Windows release-race;
future work to restructure DecrementGuard would be FFB-5+ if filed.

No source changes.
oferchen added a commit that referenced this pull request Aug 24, 2026
…delta path via PIP-5 default flip

PR #4666 (PIP-3 + PIP-5) made parallel-receive-delta a default feature
across cli, core, transfer, and engine. The four CI interop workflows
build with default features and run the 72-cell harness against rsync
3.0.9/3.1.3/3.4.1/3.4.2 over daemon and SSH transports - so every push
to master since 647ada6 exercises the parallel path on cells that
trip the Path B heuristic (file_count > 100 or total_size > 64 MiB),
implicitly satisfying PIP-4 without an explicit one-shot re-run.

Document records the build evidence, the wire-up evidence in
receiver/mod.rs::dispatch_receiver_strategy, six representative
interop cells whose datasets cross the threshold, and the re-open
triggers (feature removed from default set, gate replaced, thresholds
raised above cell sizes, or new workflow added with non-default
features).
oferchen added a commit that referenced this pull request Aug 24, 2026
…#4679)

Adds the end-to-end production-path bench harness for the parallel-
receive-delta promotion chain. PIP-6 is the third bench in the
sequence after BR-3i.f (#2502, apply-loop) and BR-3j.f (#2508,
post-DashMap re-bench).

Scope: drives a real oc-rsync client against a real oc-rsync daemon
over rsync:// loopback, on workload shapes calibrated to the Path B
dispatch boundary (file_count > 100 || total_size > 64 MiB) that
PIP-3+5 (PR #4666) wired into ReceiverContext::dispatch_receiver_strategy.

Comparison shape: same workload, two oc-rsync binaries (default-features
build vs --no-default-features --features 'zstd lz4 xattr iconv').
The no-parallel build trips the parallel_unavailable fallback path
in crates/transfer/src/receiver/mod.rs and always picks sequential.

Workload matrix:
- single_large_file (1x1 GiB, parallel by byte threshold)
- many_small_files (10_000x4 KiB, parallel by count)
- boundary_under (50 files, 32 MiB, sequential control)
- boundary_over (200 files, 32 MiB, parallel above count)
- mixed_directory (1_000 files, ~600 MiB, parallel)

Decision criteria:
- Win on >= 2 of 5 shapes (parallel_wall / sequential_wall <= 0.9)
- No shape regresses by more than 5%
- boundary_under within +/-3% (harness control)

Bench compiles; numbers capture is the follow-up. The section-4 table
in docs/design/parallel-receive-delta-default-on.md is the target for
the wall-clock data.
oferchen added a commit that referenced this pull request Aug 24, 2026
… receiver corruption) (#4725)

PIP-4 (#4720) added the `parallel-threshold-trip` interop scenario that
crosses `PARALLEL_RECEIVE_FILE_COUNT_THRESHOLD = 100` and exposed a real
corruption bug: the receiver writes wrong bytes for the first dispatched
file (`parallel_threshold/file_1.txt`) whenever a transfer trips the
parallel-receive-delta dispatch path. The bug reproduces on stock
`cargo build --release` because PIP-5 (#4666) flipped the feature into
the default set across the workspace.

This PR ships the immediate mitigation so default builds are safe again
while PIP-7 investigates the receiver-side corruption:

1. Remove `parallel-receive-delta` from `default = [...]` in the
   workspace `Cargo.toml`, `crates/transfer/Cargo.toml`, and
   `crates/engine/Cargo.toml`. The feature stays defined and remains
   opt-in via `--features parallel-receive-delta` for testing.
2. Remove the `parallel-threshold-trip` matrix entry from
   `tools/ci/run_interop.sh` along with its setup, cleanup, and verify
   branches. The threshold constants in `receiver/mod.rs` stay in place.
3. Add `docs/design/pip-7-parallel-receive-delta-receiver-corruption-2026-05-22.md`
   tracking the open investigation, suspected locations
   (`crates/engine/src/concurrent_delta/parallel_apply.rs` and
   `crates/transfer/src/delta_pipeline/parallel.rs`), reproduction
   recipe, and acceptance criteria for re-promotion.
4. Flag the deferred-pending-PIP-7 status in `README.md`,
   `CHANGELOG.md`, `docs/design/parallel-receive-delta-default-on.md`,
   `docs/design/pip-4-closure-2026-05-21.md`, and
   `docs/design/br-6-sign-off-check-in-2026-05-21.md` so the shipped
   claims no longer read as if default builds exercise the parallel
   receive-delta path.

The `ParallelDeltaApplier`, `dispatch_receiver_strategy()`,
`enable_parallel_receive_delta()`, and the `OC_RSYNC_FORCE_PARALLEL`
debug env knob from PIP-4 are intentionally retained; they remain
reachable when the feature is opted into so the PIP-7 investigation can
iterate against them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant