|
NAMEAlgorithm::Backoff::Fibonacci - Backoff using Fibonacci sequence VERSIONThis document describes version 0.009 of Algorithm::Backoff::Fibonacci (from Perl distribution Algorithm-Backoff), released on 2019-06-20. SYNOPSIS use Algorithm::Backoff::Fibonacci;
# 1. instantiate
my $ab = Algorithm::Backoff::Fibonacci->new(
#consider_actual_delay => 1, # optional, default 0
#max_actual_duration => 0, # optional, default 0 (retry endlessly)
#max_attempts => 0, # optional, default 0 (retry endlessly)
#jitter_factor => 0.25, # optional, default 0
initial_delay1 => 2, # required
initial_delay2 => 3, # required
#max_delay => 20, # optional
#delay_on_success => 0, # optional, default 0
);
# 2. log success/failure and get a new number of seconds to delay, timestamp is
# optional but must be monotonically increasing.
my $secs;
$secs = $ab->failure(); # => 2 (= initial_delay1)
$secs = $ab->failure(); # => 3 (= initial_delay2)
$secs = $ab->failure(); # => 5 (= 2+3)
$secs = $ab->failure(); # => 8 (= 3+5)
sleep 1;
$secs = $ab->failure(); # => 12 (= 5+8 -1)
$secs = $ab->failure(); # => 20 (= min(13+8, 20) = max_delay)
$secs = $ab->success(); # => 0 (= delay_on_success)
Illustration using CLI show-backoff-delays (10 failures followed by 3 successes): % show-backoff-delays -a Fibonacci --initial-delay1 0 --initial-delay2 1 \
0 0 0 0 0 0 0 0 0 0 1 1 1
0
1
1
2
3
5
8
13
21
34
0
0
0
DESCRIPTIONThis backoff algorithm calculates the next delay using Fibonacci sequence. For example, if the two initial numbers are 2 and 3: 2, 3, 5, 8, 13, 21, ... "initial_delay1" and "initial_delay2" are required. The other attributes are optional. There are limits on the number of attempts (`max_attempts`) and total duration (`max_actual_duration`). It is recommended to add a jitter factor, e.g. 0.25 to add some randomness to avoid "thundering herd problem". METHODSnewUsage: new(%args) -> obj This function is not exported. Arguments ('*' denotes required arguments):
Return value: (obj) HOMEPAGEPlease visit the project's homepage at <https://metacpan.org/release/Algorithm-Backoff>. SOURCESource repository is at <https://github.com/perlancar/perl-Algorithm-Backoff>. BUGSPlease report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Algorithm-Backoff> When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. SEE ALSO<https://en.wikipedia.org/wiki/Fibonacci_number> Algorithm::Backoff Other "Algorithm::Backoff::*" classes. AUTHORperlancar <perlancar@cpan.org> COPYRIGHT AND LICENSEThis software is copyright (c) 2019 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
|