Function slottle::fibonacci [−][src]
pub fn fibonacci(base: Duration, max: Duration) -> Interval
Create fibonacci delay interval base on failure count.
Give base
as an "unit" duration and max
as maximum duration. This function
will calculate all available fibonacci sequence items (without first 2 item [0, 1]
).
The fibonacci sequence size will also be used for the log size of throttle.
Algorithm
ⓘ
// let base = Duration::from_millis(10); // for example // let max = Duration::from_millis(60); // for example // let max_ratio = 6; // == max / base // let fibo_seq = [1, 2, 3, 5]; // last item always <= max_ratio // assert_eq!(throttle_log.size(), fibo_seq.len()); let how_long_should_delay = fibo_seq[throttle_log.failure_count()] * base;
Panic
This function will panic when max < base
or base == Duration::new(0, 0)
.