Struct grin_util::RateCounter
source · pub struct RateCounter { /* private fields */ }
Expand description
A rate counter tracks the number of transfers, the amount of data exchanged and the rate of transfer (via a few timers) over the last minute. The counter does not try to be accurate and update times proactively, instead it only does so lazily. As a result, produced rates are worst-case estimates.
Implementations§
source§impl RateCounter
impl RateCounter
sourcepub fn new() -> RateCounter
pub fn new() -> RateCounter
Instantiate a new rate counter
sourcepub fn inc(&mut self, bytes: u64)
pub fn inc(&mut self, bytes: u64)
Increments number of bytes transferred, updating counts and rates.
sourcepub fn inc_quiet(&mut self, bytes: u64)
pub fn inc_quiet(&mut self, bytes: u64)
Increments number of bytes without updating the count or rate. We filter out 0 last_min_times when calculating rate. Used during txhashset.zip download to track bytes downloaded without treating a peer as abusive (too high a rate of download).
sourcepub fn bytes_per_min(&self) -> u64
pub fn bytes_per_min(&self) -> u64
Number of bytes counted in the last minute. Includes “quiet” byte increments.
sourcepub fn count_per_min(&self) -> u64
pub fn count_per_min(&self) -> u64
Count of increases in the last minute. Excludes “quiet” byte increments.
sourcepub fn elapsed_since_last_msg(&self) -> Option<u64>
pub fn elapsed_since_last_msg(&self) -> Option<u64>
Elapsed time in ms since the last entry. We use this to rate limit when sending.