Skip to content

feat: add EMA throughput tracker and dynamic buffer sizing to BufferPool - #3032

Merged
oferchen merged 1 commit into
masterfrom
feature/buffer-pool-ema
Mar 28, 2026
Merged

oferchen merged 1 commit into
masterfrom
feature/buffer-pool-ema

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add ThroughputTracker - a lock-free EMA-based throughput estimator with warmup period (first 8 samples use simple average, then switches to exponential smoothing)
  • Add BufferPool::with_throughput_tracking() builder that enables optional dynamic buffer sizing based on observed transfer throughput
  • Add BufferPool::recommended_buffer_size() targeting ~10ms of data per buffer, clamped between 4 KiB and 256 KiB (or memory_cap/4)
  • Wire throughput recording into execute_transfer after each file copy completes

Test plan

  • Unit tests for EMA calculation accuracy (single sample, warmup average, EMA smoothing)
  • Tests for warmup-to-EMA transition behavior
  • Tests for recommended_buffer_size at various throughput levels (low/medium/high)
  • Tests for bounds clamping (min 4 KiB, max 256 KiB, memory_cap/4)
  • Thread safety tests (concurrent record + read from multiple threads)
  • Integration tests showing buffer sizes adapt over time with changing throughput
  • Verify zero-cost when tracking disabled (no tracker allocated, no atomics)
  • All existing BufferPool tests pass unchanged

Add ThroughputTracker that maintains an Exponential Moving Average of
transfer throughput (bytes/sec) using lock-free atomics. The tracker
uses a warmup period (first 8 samples as simple average) before
switching to EMA smoothing, avoiding initial zero-state bias.

BufferPool gains optional throughput tracking via with_throughput_tracking()
builder method. When enabled, recommended_buffer_size() returns a dynamic
size targeting ~10ms of data per buffer, clamped between 4 KiB and 256 KiB
(or memory_cap/4). Zero-cost when not enabled - no atomics or allocations.

Wire throughput recording into execute_transfer after each file copy
completes, feeding elapsed time and bytes transferred to the pool.
@github-actions github-actions Bot added the enhancement New feature or request label Mar 28, 2026
@oferchen
oferchen merged commit e49e79e into master Mar 28, 2026
35 checks passed
@oferchen
oferchen deleted the feature/buffer-pool-ema branch March 28, 2026 13:48
oferchen added a commit that referenced this pull request May 1, 2026
…ool (#3032)

Add ThroughputTracker that maintains an Exponential Moving Average of
transfer throughput (bytes/sec) using lock-free atomics. The tracker
uses a warmup period (first 8 samples as simple average) before
switching to EMA smoothing, avoiding initial zero-state bias.

BufferPool gains optional throughput tracking via with_throughput_tracking()
builder method. When enabled, recommended_buffer_size() returns a dynamic
size targeting ~10ms of data per buffer, clamped between 4 KiB and 256 KiB
(or memory_cap/4). Zero-cost when not enabled - no atomics or allocations.

Wire throughput recording into execute_transfer after each file copy
completes, feeding elapsed time and bytes transferred to the pool.
oferchen added a commit that referenced this pull request May 5, 2026
…ool (#3032)

Add ThroughputTracker that maintains an Exponential Moving Average of
transfer throughput (bytes/sec) using lock-free atomics. The tracker
uses a warmup period (first 8 samples as simple average) before
switching to EMA smoothing, avoiding initial zero-state bias.

BufferPool gains optional throughput tracking via with_throughput_tracking()
builder method. When enabled, recommended_buffer_size() returns a dynamic
size targeting ~10ms of data per buffer, clamped between 4 KiB and 256 KiB
(or memory_cap/4). Zero-cost when not enabled - no atomics or allocations.

Wire throughput recording into execute_transfer after each file copy
completes, feeding elapsed time and bytes transferred to the 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