Skip to content

feat: adapt parallel delta work queue to workload + core count - #4012

Merged
oferchen merged 1 commit into
masterfrom
feat/adaptive-work-queue-capacity
May 14, 2026
Merged

oferchen merged 1 commit into
masterfrom
feat/adaptive-work-queue-capacity

Conversation

@oferchen

Copy link
Copy Markdown
Owner

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:

Average target size Multiplier Rationale
< 64 KiB 8x CPU/syscall-bound; deep queue avoids worker starvation
64 KiB – 1 MiB 4x Mixed
> 1 MiB 2x I/O-bound; deeper queue wastes memory
0 (unknown) 2x Default, identical to old 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 variant
  • new_bypass_adaptive(worker_count, avg_target_size) — bypass variant

Existing new() / new_bypass() are preserved unchanged for callers without workload information.

ThresholdDeltaPipeline::promote_to_parallel() now computes the average target size from the buffered DeltaWork items 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 explicit worker_count so the receiver can pass its configured thread budget when it differs from rayon's pool.

Test plan

  • adaptive_capacity_small_files_uses_8x_multiplier
  • adaptive_capacity_medium_files_uses_4x_multiplier
  • adaptive_capacity_large_files_uses_2x_multiplier
  • adaptive_capacity_unknown_workload_falls_back_to_default
  • adaptive_capacity_floor_keeps_pipeline_usable (worker_count == 0 edge case)
  • average_target_size_empty_returns_zero
  • average_target_size_computes_arithmetic_mean
  • average_target_size_saturates_at_u64_max (long tail of huge files)

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.
@github-actions github-actions Bot added the enhancement New feature or request label May 13, 2026
@oferchen
oferchen merged commit d8451eb into master May 14, 2026
39 checks passed
@oferchen
oferchen deleted the feat/adaptive-work-queue-capacity branch May 14, 2026 14:57
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant