pub struct SamplingState { /* private fields */ }Expand description
Runtime sampling state. Tracks counters and drives both the VU-threshold gate and Vitter’s Algorithm R reservoir gate.
Implementations§
Source§impl SamplingState
impl SamplingState
pub fn new(params: SamplingParams) -> Self
Sourcepub fn set_active_vus(&mut self, vus: usize)
pub fn set_active_vus(&mut self, vus: usize)
Call on each coordinator tick when the active VU count may have changed.
When vus > vu_threshold (and vu_threshold != 0), caps the collection
rate to threshold / vus. Otherwise rate is 1.0 (collect everything).
Sourcepub fn record_request(&mut self, success: bool)
pub fn record_request(&mut self, success: bool)
Always call for every completed request. Updates the unsampled counters regardless of whether this result will be stored in the reservoir.
Sourcepub fn should_collect(&mut self) -> bool
pub fn should_collect(&mut self) -> bool
VU-threshold gate: returns true if this result should proceed toward
the reservoir. At sample_rate >= 1.0 always returns true.
Sourcepub fn reservoir_slot(&mut self, results_len: usize) -> ReservoirAction
pub fn reservoir_slot(&mut self, results_len: usize) -> ReservoirAction
Reservoir gate (Vitter’s Algorithm R). Call only when should_collect()
returned true.
Increments the internal seen-counter and returns the storage instruction:
Push— buffer not yet full; append.Replace(j)— buffer full; replace slotj(uniform random).Discard— buffer full; this result lost the lottery.
pub fn total_requests(&self) -> usize
pub fn total_failures(&self) -> usize
pub fn sample_rate(&self) -> f64
pub fn min_sample_rate(&self) -> f64
Auto Trait Implementations§
impl Freeze for SamplingState
impl !RefUnwindSafe for SamplingState
impl !Send for SamplingState
impl !Sync for SamplingState
impl Unpin for SamplingState
impl UnsafeUnpin for SamplingState
impl !UnwindSafe for SamplingState
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