pub struct AdaptiveLoop { /* private fields */ }Expand description
Closed-loop wrapper: drives a RateLimiter from netforge
EngineStats deltas. Call AdaptiveLoop::tick every batch.
Decision rules:
tx_dropsincreased since the last tick → packets are being lost on the way out (NIC ring full, kernel back-pressure). Halve the target rate viaAdaptiveRate::report_drops.tx_dropsflat ANDtx_packetsincreased → callAdaptiveRate::report_success; after 10 clean ticks the rate creeps back up by 5% of the configured ceiling.- The applied rate is propagated to the wrapped
RateLimiterso the per-batch consume path actually slows down.
This is the interlock between the observed loss signal and the enforced token bucket. Without it the bucket would stay pegged at the configured ceiling regardless of what the wire is doing.
Implementations§
Source§impl AdaptiveLoop
impl AdaptiveLoop
Sourcepub fn new(max_pps: u64) -> Self
pub fn new(max_pps: u64) -> Self
Construct with max_pps as the ceiling. Initial enforced rate
starts at half (max_pps / 2) per AdaptiveRate::new.
Sourcepub fn tick(&mut self, tx_packets: u64, tx_drops: u64) -> u64
pub fn tick(&mut self, tx_packets: u64, tx_drops: u64) -> u64
Process a fresh stats snapshot and return the enforced rate.
First call seeds the baseline and returns the initial rate without classifying anything.
Sourcepub fn apply(&self, limiter: &mut RateLimiter)
pub fn apply(&self, limiter: &mut RateLimiter)
Apply the loop’s current target to a RateLimiter. Call
after every tick — cheap (one assignment) and safe.
Sourcepub fn current_pps(&self) -> u64
pub fn current_pps(&self) -> u64
Current enforced rate.
Auto Trait Implementations§
impl Freeze for AdaptiveLoop
impl RefUnwindSafe for AdaptiveLoop
impl Send for AdaptiveLoop
impl Sync for AdaptiveLoop
impl Unpin for AdaptiveLoop
impl UnsafeUnpin for AdaptiveLoop
impl UnwindSafe for AdaptiveLoop
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more