pub struct RateModel { /* private fields */ }Expand description
One lane’s throughput estimate in samples per second. See the module doc.
Implementations§
Source§impl RateModel
impl RateModel
Sourcepub const fn new(initial_guess: f64) -> Self
pub const fn new(initial_guess: f64) -> Self
An uncalibrated model starting from initial_guess samples per second. The
guess only matters for reporting (Self::rate); an uncalibrated lane’s first
chunk is ChunkPolicy::first_chunk_samples long regardless.
Sourcepub fn calibrated(rate: f64) -> Self
pub fn calibrated(rate: f64) -> Self
A model already calibrated at rate (carried over from an earlier epoch of the
same lane, e.g. the previous tilt-video frame), so no calibration chunk is spent.
A non-finite or non-positive rate yields an uncalibrated model instead.
Sourcepub fn staggered(rate: f64) -> Self
pub fn staggered(rate: f64) -> Self
Self::calibrated at rate, whose first chunk is only half the size its rate
asks for (Self::take_first_chunk_scale yields Some(0.5) once), so this lane
runs half a chunk out of phase with another lane of the same worker that starts
from Self::calibrated. An unusable rate yields an uncalibrated model with no
scale: there is no calibrated first chunk to halve.
Sourcepub const fn take_first_chunk_scale(&mut self) -> Option<f64>
pub const fn take_first_chunk_scale(&mut self) -> Option<f64>
Returns the factor to apply to this lane’s first calibrated chunk and clears it,
so every later call yields None. Always None for a model not built by
Self::staggered.
Sourcepub const fn with_smoothing(self, weight_of_new: f64) -> Self
pub const fn with_smoothing(self, weight_of_new: f64) -> Self
Replaces the moving-average weight of a new measurement; clamped to
[0.01, 1.0] (1.0 means “always trust the latest chunk”).
Sourcepub const fn is_calibrated(&self) -> bool
pub const fn is_calibrated(&self) -> bool
Whether at least one real measurement has replaced the guess.
Sourcepub const fn estimate(&self) -> Option<f64>
pub const fn estimate(&self) -> Option<f64>
The calibrated estimate only (None while uncalibrated) – what a caller
carries into the next epoch with Self::calibrated.
Sourcepub const fn observations(&self) -> u32
pub const fn observations(&self) -> u32
Measurements folded in so far.
Sourcepub fn observe(
&mut self,
done: u32,
elapsed: Duration,
reported: Option<f64>,
) -> Option<f64>
pub fn observe( &mut self, done: u32, elapsed: Duration, reported: Option<f64>, ) -> Option<f64>
Folds in one finished chunk: done samples in elapsed wall time, with the
lane’s own reported marginal rate preferred when it is valid. Returns the
measurement used, or None (model unchanged) when there was nothing to measure.
Sourcepub fn chunk_samples(&self, policy: &ChunkPolicy) -> u32
pub fn chunk_samples(&self, policy: &ChunkPolicy) -> u32
The size of this lane’s next chunk under policy: the calibration chunk while
uncalibrated, otherwise ChunkPolicy::samples_for_rate of the estimate.