Struct tor_basic_utils::retry::RetryDelay
source · pub struct RetryDelay { /* private fields */ }
Expand description
An implementation for retrying a remote operation based on a decorrelated jitter schedule.
The algorithm used here has several desirable properties:
- It is randomized, so that multiple timeouts don’t have a danger of getting synchronized with each other and hammering the same servers all at once.
- It tends on average to wait longer and longer over time, so that if the server is down, it won’t get pummeled by a zillion failing clients when it comes back up.
- It has a chance of retrying promptly, which results in better client performance on average.
For a more full specification, see dir-spec.txt
.
Implementations§
source§impl RetryDelay
impl RetryDelay
sourcepub fn from_msec(base_delay_msec: u32) -> Self
pub fn from_msec(base_delay_msec: u32) -> Self
Construct a new RetryDelay from a given base delay in milliseconds.
The base delay defines the lowest possible interval that can be returned.
Limitations
If the base delay is less than 1000, a base delay of 1000 is used instead, since that’s what the C tor implementation does.
sourcepub fn from_duration(d: Duration) -> Self
pub fn from_duration(d: Duration) -> Self
Construct a new RetryDelay from a given base delay.
See from_msec for more information.
sourcepub fn next_delay<R: Rng>(&mut self, rng: &mut R) -> Duration
pub fn next_delay<R: Rng>(&mut self, rng: &mut R) -> Duration
Return the next delay to be used (as a Duration
),
according to a given random number generator.
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Return this RetryDelay
to its original state.
Trait Implementations§
source§impl Clone for RetryDelay
impl Clone for RetryDelay
source§fn clone(&self) -> RetryDelay
fn clone(&self) -> RetryDelay
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more