Expand description
Adaptive concurrency + throughput control (pure control logic).
This module is the brain and the gate of snapdir’s adaptive transfer
tuning, but it deliberately performs no network or real I/O and reads
no real clock or system samplers itself — every external signal (CPU,
RSS, elapsed time, per-op outcomes) is injected. That keeps the controller
fully deterministic and unit-testable; wiring it into the live transfer
loops (and feeding it snapdir_core::resources samples + a real monotonic
clock) is a later gate.
Three pieces:
AdaptiveGate— a resizable concurrency permit pool shared by both transfer backends. It exposes an asyncacquire(tokio semaphore) for the futures path and a zero-dependency blockingacquire_blocking(mutex + condvar) for the rayon path;set_limitretunes both live.AdaptiveController— the control law (slow-start → AIMD, latency gradient, congestion backoff with cooldown, CPU/memory guardrails, periodic re-probing) that turns injected op samples + metrics into aDecision(next concurrency limit + target byte-rate).- Supporting value types:
AdaptivePolicy,OpSample,OpResult,Decision.
Structs§
- Adaptive
Controller - The adaptive control brain.
- Adaptive
Gate - A resizable concurrency permit pool shared by both transfer backends.
- Adaptive
Policy - The controller’s tuning policy (its view of config; the
TransferConfigintegration is a later gate). - Blocking
Gate Permit - RAII guard for a blocking permit acquired from an
AdaptiveGate. Releases the permit (and notifies one waiter) on drop. - Controller
Driver - Shared, live bridge between a pure
AdaptiveControllerand the running transfer backends. - Decision
- The controller’s output for one
tick: the next concurrency limit and an optional target byte-rate. - Gate
Permit - RAII guard for an async permit acquired from an
AdaptiveGate. Releases the permit on drop — unless the gate carries outstanding shrink debt, in which case this permit is forgotten to pay that debt down (so a shrink that happened while this permit was in flight takes effect exactly). - OpSample
- One sampled transfer operation: bytes moved, observed latency, and outcome.
Enums§
- OpResult
- Outcome class of a single transfer operation, fed to
AdaptiveController::record_op.
Functions§
- p95_
object_ size - Computes the 95th-percentile of a set of object sizes (the memory-budget
denominator the controller’s
tickexpects). An empty set yields0(memory guardrail disabled). The slice is cloned + sorted locally so the caller’s data is untouched.
Type Aliases§
- Mono
Time - Injected monotonic timestamp. The controller never reads a real clock; the
caller passes a monotonically non-decreasing value (real code:
Instant::now(); tests: a fake counter). Stored as nanoseconds since an arbitrary epoch so the type is triviallyCopyand deterministic.