Repository navigation
feat: adapt parallel delta work queue to workload + core count - #4012
Merged
Merged
Conversation
The bounded work queue capacity was previously fixed at 2 * worker_count regardless of workload. Small-file transfers starved workers because syscall overhead per file dominated I/O time and the shallow queue couldn't supply enough in-flight items to keep all rayon threads busy. Add `ParallelDeltaPipeline::new_adaptive(worker_count, avg_target_size)` and `new_bypass_adaptive(...)` that scale the queue depth based on the workload: - avg < 64 KiB -> 8x worker_count (CPU/syscall-bound, deep queue) - 64 KiB - 1 MiB -> 4x worker_count (mixed) - avg > 1 MiB -> 2x worker_count (I/O-bound, shallow queue) - avg == 0 -> 2x worker_count (workload unknown, default) The threshold dispatcher's promote_to_parallel() now computes the average target size from the buffered DeltaWork items and routes through the adaptive constructor automatically. Worker count remains rayon::current_num_threads() so the queue continues to scale with the available core count. The existing new()/new_bypass() constructors are preserved unchanged for callers that don't have workload information. Mirrors the existing work_queue::adaptive_queue_depth() heuristic but operates on an explicit worker_count so the receiver can pass its configured thread budget when it differs from rayon's pool.
2 tasks
4 tasks
oferchen
added a commit
that referenced
this pull request
May 18, 2026
The bounded work queue capacity was previously fixed at 2 * worker_count regardless of workload. Small-file transfers starved workers because syscall overhead per file dominated I/O time and the shallow queue couldn't supply enough in-flight items to keep all rayon threads busy. Add `ParallelDeltaPipeline::new_adaptive(worker_count, avg_target_size)` and `new_bypass_adaptive(...)` that scale the queue depth based on the workload: - avg < 64 KiB -> 8x worker_count (CPU/syscall-bound, deep queue) - 64 KiB - 1 MiB -> 4x worker_count (mixed) - avg > 1 MiB -> 2x worker_count (I/O-bound, shallow queue) - avg == 0 -> 2x worker_count (workload unknown, default) The threshold dispatcher's promote_to_parallel() now computes the average target size from the buffered DeltaWork items and routes through the adaptive constructor automatically. Worker count remains rayon::current_num_threads() so the queue continues to scale with the available core count. The existing new()/new_bypass() constructors are preserved unchanged for callers that don't have workload information. Mirrors the existing work_queue::adaptive_queue_depth() heuristic but operates on an explicit worker_count so the receiver can pass its configured thread budget when it differs from rayon's pool.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
The bounded work queue capacity was previously fixed at 2 * worker_count regardless of workload. Small-file transfers starved workers because syscall overhead per file dominated I/O time and the shallow queue couldn't supply enough in-flight items to keep all rayon threads busy. Add `ParallelDeltaPipeline::new_adaptive(worker_count, avg_target_size)` and `new_bypass_adaptive(...)` that scale the queue depth based on the workload: - avg < 64 KiB -> 8x worker_count (CPU/syscall-bound, deep queue) - 64 KiB - 1 MiB -> 4x worker_count (mixed) - avg > 1 MiB -> 2x worker_count (I/O-bound, shallow queue) - avg == 0 -> 2x worker_count (workload unknown, default) The threshold dispatcher's promote_to_parallel() now computes the average target size from the buffered DeltaWork items and routes through the adaptive constructor automatically. Worker count remains rayon::current_num_threads() so the queue continues to scale with the available core count. The existing new()/new_bypass() constructors are preserved unchanged for callers that don't have workload information. Mirrors the existing work_queue::adaptive_queue_depth() heuristic but operates on an explicit worker_count so the receiver can pass its configured thread budget when it differs from rayon's pool.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
The bounded work queue capacity was previously fixed at 2 * worker_count regardless of workload. Small-file transfers starved workers because syscall overhead per file dominated I/O time and the shallow queue couldn't supply enough in-flight items to keep all rayon threads busy. Add `ParallelDeltaPipeline::new_adaptive(worker_count, avg_target_size)` and `new_bypass_adaptive(...)` that scale the queue depth based on the workload: - avg < 64 KiB -> 8x worker_count (CPU/syscall-bound, deep queue) - 64 KiB - 1 MiB -> 4x worker_count (mixed) - avg > 1 MiB -> 2x worker_count (I/O-bound, shallow queue) - avg == 0 -> 2x worker_count (workload unknown, default) The threshold dispatcher's promote_to_parallel() now computes the average target size from the buffered DeltaWork items and routes through the adaptive constructor automatically. Worker count remains rayon::current_num_threads() so the queue continues to scale with the available core count. The existing new()/new_bypass() constructors are preserved unchanged for callers that don't have workload information. Mirrors the existing work_queue::adaptive_queue_depth() heuristic but operates on an explicit worker_count so the receiver can pass its configured thread budget when it differs from rayon's pool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The bounded work queue feeding rayon workers in the parallel delta pipeline was fixed at 2 × worker_count, regardless of workload. Small-file transfers starved workers because per-file syscall overhead dominated I/O time and the shallow queue couldn't supply enough in-flight items to keep all cores busy. Large-file transfers paid for queue memory they didn't need.
What's adaptive now
Worker count continues to scale with
rayon::current_num_threads(). The multiplier now scales with workload:new()A capacity floor of 2 guarantees the bounded channel is constructible even when
worker_count == 0.API
New constructors on
ParallelDeltaPipeline:new_adaptive(worker_count, avg_target_size)— reorder-buffered variantnew_bypass_adaptive(worker_count, avg_target_size)— bypass variantExisting
new()/new_bypass()are preserved unchanged for callers without workload information.ThresholdDeltaPipeline::promote_to_parallel()now computes the average target size from the bufferedDeltaWorkitems and routes through the adaptive constructors automatically, so production transfers benefit transparently.Mirrors the existing
work_queue::adaptive_queue_depth()heuristic but operates on an explicitworker_countso the receiver can pass its configured thread budget when it differs from rayon's pool.Test plan
adaptive_capacity_small_files_uses_8x_multiplieradaptive_capacity_medium_files_uses_4x_multiplieradaptive_capacity_large_files_uses_2x_multiplieradaptive_capacity_unknown_workload_falls_back_to_defaultadaptive_capacity_floor_keeps_pipeline_usable(worker_count == 0 edge case)average_target_size_empty_returns_zeroaverage_target_size_computes_arithmetic_meanaverage_target_size_saturates_at_u64_max(long tail of huge files)