Algorithm-Backoff

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN


Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.

  4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License.  However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.

  5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.

README  view on Meta::CPAN

        and original_delay * (1+jitter_factor). Jitters are usually added to
        avoid so-called "thundering herd" problem.

        The jitter will be applied to delay on failure as well as on
        success.

    *   max_attempts => *uint* (default: 0)

        Maximum number consecutive failures before giving up.

        0 means to retry endlessly without ever giving up. 1 means to give
        up after a single failure (i.e. no retry attempts). 2 means to retry
        once after a failure. Note that after a success, the number of
        attempts is reset (as expected). So if max_attempts is 3, and if you
        fail twice then succeed, then on the next failure the algorithm will
        retry again for a maximum of 3 times.

    Return value: (obj)

  success
    Usage:

lib/Algorithm/Backoff.pm  view on Meta::CPAN

);

our %attr_max_attempts = (
    max_attempts => {
        summary => 'Maximum number consecutive failures before giving up',
        schema => 'uint*',
        default => 0,
        tags => ['common'],
        description => <<'_',

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

_
    },
);

our %attr_jitter_factor = (

lib/Algorithm/Backoff.pm  view on Meta::CPAN

random number between original_delay * (1-jitter_factor) and original_delay *
(1+jitter_factor). Jitters are usually added to avoid so-called "thundering
herd" problem.

The jitter will be applied to delay on failure as well as on success.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.


=back

Return value:  (obj)

lib/Algorithm/Backoff/Constant.pm  view on Meta::CPAN

This document describes version 0.010 of Algorithm::Backoff::Constant (from Perl distribution Algorithm-Backoff), released on 2024-02-24.

=head1 SYNOPSIS

 use Algorithm::Backoff::Constant;

 # 1. instantiate

 my $ab = Algorithm::Backoff::Constant->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, # optional, set to positive value to add randomness
     delay                  => 2, # required
     #delay_on_success      => 0, # optional, default 0
 );

 # 2. log success/failure and get a new number of seconds to delay, timestamp is
 # optional argument (default is current time) but must be monotonically
 # increasing.

 my $secs = $ab->failure(1554652553); # => 2

lib/Algorithm/Backoff/Constant.pm  view on Meta::CPAN

spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

=item * B<max_delay> => I<ufloat>

Maximum delay time, in seconds.

=item * B<min_delay> => I<ufloat> (default: 0)

lib/Algorithm/Backoff/Exponential.pm  view on Meta::CPAN

This document describes version 0.010 of Algorithm::Backoff::Exponential (from Perl distribution Algorithm-Backoff), released on 2024-02-24.

=head1 SYNOPSIS

 use Algorithm::Backoff::Exponential;

 # 1. instantiate

 my $ab = Algorithm::Backoff::Exponential->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_delay          => 5, # required
     #max_delay             => 100, # optional
     #exponent_base         => 2, # optional, default 2 (binary exponentiation)
     #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.

lib/Algorithm/Backoff/Exponential.pm  view on Meta::CPAN

spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

=item * B<max_delay> => I<ufloat>

Maximum delay time, in seconds.

=item * B<min_delay> => I<ufloat> (default: 0)

lib/Algorithm/Backoff/Fibonacci.pm  view on Meta::CPAN

This document describes version 0.010 of Algorithm::Backoff::Fibonacci (from Perl distribution Algorithm-Backoff), released on 2024-02-24.

=head1 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.

lib/Algorithm/Backoff/Fibonacci.pm  view on Meta::CPAN

spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

=item * B<max_delay> => I<ufloat>

Maximum delay time, in seconds.

=item * B<min_delay> => I<ufloat> (default: 0)

lib/Algorithm/Backoff/LILD.pm  view on Meta::CPAN

This document describes version 0.010 of Algorithm::Backoff::LILD (from Perl distribution Algorithm-Backoff), released on 2024-02-24.

=head1 SYNOPSIS

 use Algorithm::Backoff::LILD;

 # 1. instantiate

 my $ab = Algorithm::Backoff::LILD->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
     min_delay              => 1, # optional, default 0
     #max_delay             => 100, # optional
     initial_delay              =>  3, # required
     delay_increment_on_failure =>  4, # required
     delay_increment_on_success => -5, # required
 );

 # 2. log success/failure and get a new number of seconds to delay, timestamp is
 # optional but must be monotonically increasing.

lib/Algorithm/Backoff/LILD.pm  view on Meta::CPAN

spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

=item * B<max_delay> => I<ufloat>

Maximum delay time, in seconds.

=item * B<min_delay> => I<ufloat> (default: 0)

lib/Algorithm/Backoff/LIMD.pm  view on Meta::CPAN

This document describes version 0.010 of Algorithm::Backoff::LIMD (from Perl distribution Algorithm-Backoff), released on 2024-02-24.

=head1 SYNOPSIS

 use Algorithm::Backoff::LIMD;

 # 1. instantiate

 my $ab = Algorithm::Backoff::LIMD->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
     min_delay              => 1, # optional, default 0
     #max_delay             => 100, # optional
     initial_delay              => 2,   # required
     delay_increment_on_failure => 4,   # required
     delay_multiple_on_success  => 0.2, # required
 );

 # 2. log success/failure and get a new number of seconds to delay, timestamp is
 # optional but must be monotonically increasing.

lib/Algorithm/Backoff/LIMD.pm  view on Meta::CPAN

spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

=item * B<max_delay> => I<ufloat>

Maximum delay time, in seconds.

=item * B<min_delay> => I<ufloat> (default: 0)

lib/Algorithm/Backoff/MILD.pm  view on Meta::CPAN

This document describes version 0.010 of Algorithm::Backoff::MILD (from Perl distribution Algorithm-Backoff), released on 2024-02-24.

=head1 SYNOPSIS

 use Algorithm::Backoff::MILD;

 # 1. instantiate

 my $ab = Algorithm::Backoff::MILD->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
     #min_delay             => 2, # optional, default 0
     #max_delay             => 100, # optional
     initial_delay              => 1,   # required
     delay_multiple_on_failure  => 1.5, # required
     delay_increment_on_success => -2,  # required
 );

 # 2. log success/failure and get a new number of seconds to delay, timestamp is
 # optional but must be monotonically increasing.

lib/Algorithm/Backoff/MILD.pm  view on Meta::CPAN

spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

=item * B<max_delay> => I<ufloat>

Maximum delay time, in seconds.

=item * B<min_delay> => I<ufloat> (default: 0)

lib/Algorithm/Backoff/MIMD.pm  view on Meta::CPAN

This document describes version 0.010 of Algorithm::Backoff::MIMD (from Perl distribution Algorithm-Backoff), released on 2024-02-24.

=head1 SYNOPSIS

 use Algorithm::Backoff::MIMD;

 # 1. instantiate

 my $ab = Algorithm::Backoff::MIMD->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
     min_delay              => 2, # optional, default 0
     #max_delay             => 100, # optional
     initial_delay              => 3,   # required
     delay_multiple_on_failure  => 2,   # required
     delay_multiple_on_success  => 0.5, # required
 );

 # 2. log success/failure and get a new number of seconds to delay, timestamp is
 # optional but must be monotonically increasing.

lib/Algorithm/Backoff/MIMD.pm  view on Meta::CPAN

spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.

=item * B<max_attempts> => I<uint> (default: 0)

Maximum number consecutive failures before giving up.

0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.

=item * B<max_delay> => I<ufloat>

Maximum delay time, in seconds.

=item * B<min_delay> => I<ufloat> (default: 0)



( run in 1.501 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )