Algorithm-Backoff-RetryTimeouts
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
NAME
Algorithm::Backoff::RetryTimeouts - A backoff-style retry algorithm
with adjustable timeout support
VERSION
version v1.0.0
SYNOPSIS
use Algorithm::Backoff::RetryTimeouts;
my $retry_algo = Algorithm::Backoff::RetryTimeouts->new(
# common adjustments (defaults shown)
max_attempts => 8,
max_actual_duration => 50,
jitter_factor => 0.1,
timeout_jitter_factor => 0.1,
adjust_timeout_factor => 0.5,
min_adjust_timeout => 5,
# other defaults
initial_delay => sqrt(2),
exponent_base => sqrt(2),
delay_on_success => 0,
min_delay => 0,
max_delay => undef,
consider_actual_delay => 1,
);
my ($delay, $timeout);
$timeout = $retry_algo->timeout;
my $is_successful = 0;
while (!$is_successful) {
$actionee->timeout( $timeout );
$is_successful = $actionee->do_the_thing;
($delay, $timeout) = $is_successful ? $retry_algo->success : $retry_algo->failure;
die "Ran out of time" if $delay == -1;
sleep $delay;
}
DESCRIPTION
This module is a subclass of Algorithm::Backoff::Exponential that adds
support for adjustable timeouts during each retry. This also comes with
a sane set of defaults as a good baseline for most kinds of retry
operations.
A combination of features solves for most problems that would arise
from retry operations:
* Maximum attempts - Forces the algorithm to give up if repeated
attempts don't yield success.
* Maximum duration - Forces the algorithm to give up if no successes
happen within a certain time frame.
* Exponential backoff - A sqrt(2) exponential delay keeps single
retries from waiting too long, while spreading out repeated retries
that may fail too quickly and run out of max attempts. This also
decreases the congestion that happens with repeated attempts.
* Jitter - Adding random jitter to the retry delays solves for the
Thundering Herd problem.
* Adjustable timeouts - Providing an adjustable timeout after each
request solves the opposite problem of exponential backoffs: slower,
unresponsive errors that gobble up all of the max duration time in
one go. Each new timeout is a certain percentage of the time left.
Typical scenario
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.774 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )