Algorithm-Backoff-RetryTimeouts
view release on metacpan or search on metacpan
Changelog for Algorithm-Backoff-RetryTimeouts
v1.0.0 2021-02-11T22:07:03
- Fix POD error (Brendan Byrd)
- Create distribution files (Andrew Hewus Fresh)
- Set _attempts / _last_timestamp even on max duration/attempt failures
(Brendan Byrd)
- Fix unnecessary delays during the first failure (Brendan Byrd)
- Add timeout_jitter_factor with a default of 10% (Brendan Byrd)
- Create Algorithm::Backoff::RetryTimeouts and unit test (Brendan Byrd)
- Initial Commit (Brendan Byrd)
CHANGES
CONTRIBUTING.md
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
cpanfile
dist.ini
lib/Algorithm/Backoff/RetryTimeouts.pm
t/00-compile.t
t/00-report-prereqs.dd
t/00-report-prereqs.t
t/basic.t
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.015, CPAN::Meta::Converter version 2.150010",
"license" : [
"artistic_2"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Algorithm-Backoff-RetryTimeouts",
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "7.1101"
}
},
"develop" : {
"requires" : {
"Dist::Zilla::PluginBundle::Author::GSG" : "0"
}
"requires" : {
"ExtUtils::MakeMaker" : "0",
"File::Spec" : "0",
"IO::Handle" : "0",
"IPC::Open3" : "0",
"Test::More" : "0"
}
}
},
"provides" : {
"Algorithm::Backoff::RetryTimeouts" : {
"file" : "lib/Algorithm/Backoff/RetryTimeouts.pm",
"version" : "v1.0.0"
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/GrantStreetGroup/Algorithm-Backoff-RetryTimeouts/issues"
},
"repository" : {
"type" : "git",
"url" : "git://github.com/GrantStreetGroup/Algorithm-Backoff-RetryTimeouts.git",
"web" : "https://github.com/GrantStreetGroup/Algorithm-Backoff-RetryTimeouts"
}
},
"version" : "v1.0.0",
"x_generated_by_perl" : "v5.18.2",
"x_serialization_backend" : "JSON::XS version 4.02",
"x_spdx_expression" : "Artistic-2.0",
"x_static_install" : 1
}
IPC::Open3: '0'
Test::More: '0'
configure_requires:
ExtUtils::MakeMaker: '7.1101'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.015, CPAN::Meta::Converter version 2.150010'
license: artistic_2
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Algorithm-Backoff-RetryTimeouts
provides:
Algorithm::Backoff::RetryTimeouts:
file: lib/Algorithm/Backoff/RetryTimeouts.pm
version: v1.0.0
requires:
Algorithm::Backoff::Exponential: '0.009'
Storable: '0'
namespace::clean: '0'
resources:
bugtracker: https://github.com/GrantStreetGroup/Algorithm-Backoff-RetryTimeouts/issues
repository: git://github.com/GrantStreetGroup/Algorithm-Backoff-RetryTimeouts.git
version: v1.0.0
x_generated_by_perl: v5.18.2
x_serialization_backend: 'YAML::Tiny version 1.73'
x_spdx_expression: Artistic-2.0
x_static_install: 1
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker 7.1101;
my %WriteMakefileArgs = (
"ABSTRACT" => "A backoff-style retry algorithm with adjustable timeout support",
"AUTHOR" => "Grant Street Group <developers\@grantstreet.com>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "7.1101"
},
"DISTNAME" => "Algorithm-Backoff-RetryTimeouts",
"LICENSE" => "artistic_2",
"NAME" => "Algorithm::Backoff::RetryTimeouts",
"PREREQ_PM" => {
"Algorithm::Backoff::Exponential" => "0.009",
"Storable" => 0,
"namespace::clean" => 0
},
"TEST_REQUIRES" => {
"ExtUtils::MakeMaker" => 0,
"File::Spec" => 0,
"IO::Handle" => 0,
"IPC::Open3" => 0,
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),
name = Algorithm-Backoff-RetryTimeouts
[@Author::GSG]
lib/Algorithm/Backoff/RetryTimeouts.pm view on Meta::CPAN
package Algorithm::Backoff::RetryTimeouts;
use utf8;
use strict;
use warnings;
use Algorithm::Backoff::Exponential;
use base qw< Algorithm::Backoff::Exponential >;
use Storable qw< dclone >;
use Time::HiRes qw< time >;
use namespace::clean;
# ABSTRACT: A backoff-style retry algorithm with adjustable timeout support
use version;
our $VERSION = 'v1.0.0'; # VERSION
#pod =head1 SYNOPSIS
#pod
#pod use Algorithm::Backoff::RetryTimeouts;
#pod
#pod my $retry_algo = Algorithm::Backoff::RetryTimeouts->new(
#pod # common adjustments (defaults shown)
#pod max_attempts => 8,
#pod max_actual_duration => 50,
#pod jitter_factor => 0.1,
#pod timeout_jitter_factor => 0.1,
#pod adjust_timeout_factor => 0.5,
#pod min_adjust_timeout => 5,
#pod
#pod # other defaults
#pod initial_delay => sqrt(2),
lib/Algorithm/Backoff/RetryTimeouts.pm view on Meta::CPAN
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Algorithm::Backoff::RetryTimeouts - A backoff-style retry algorithm with adjustable timeout support
=head1 VERSION
version v1.0.0
=head1 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),
t/00-compile.t view on Meta::CPAN
use strict;
use warnings;
# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058
use Test::More;
plan tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
my @module_files = (
'Algorithm/Backoff/RetryTimeouts.pm'
);
# no fake home requested
my @switches = (
-d 'blib' ? '-Mblib' : '-Ilib',
);
#!perl
use strict;
use warnings;
use Test::More 0.98;
use List::Util qw< min max sum >;
use Algorithm::Backoff::RetryTimeouts;
my $rt;
my $time = 0;
my $sqrt2 = sqrt(2);
subtest "Base defaults" => sub {
$rt = Algorithm::Backoff::RetryTimeouts->new(
# for the unit tests
_start_timestamp => 0,
jitter_factor => 0,
timeout_jitter_factor => 0,
);
$time = 0;
is($rt->timeout, 25, 'Initial timeout: 25');
# 1: one second attempt
);
# 7: final attempt
test_attempt(
expected_delay => -1,
expected_timeout => 5
);
};
subtest "attr: adjust_timeout_factor" => sub {
$rt = Algorithm::Backoff::RetryTimeouts->new(
adjust_timeout_factor => 0.25,
# for the unit tests
_start_timestamp => 0,
jitter_factor => 0,
timeout_jitter_factor => 0,
);
$time = 0;
is($rt->timeout, 12.5, 'Initial timeout: 12.5');
attempt_time => 1,
expected_delay => 3, # sqrt(2)^4 - 1
);
# 5: full timeout
test_attempt(
expected_delay => 0,
);
# 6: full timeout (with min_adjust_timeout trigger)
note "Prev Timeout: ".round($rt->timeout);
test_attempt(
expected_delay => 2.199, # sqrt(2)^6 = 8 - 5.801 (prev timeout)
expected_timeout => 5,
);
# 7: full timeout
test_attempt(
expected_delay => 6.314, # sqrt(2)^7 - 5
expected_timeout => 5,
);
# 8: final attempt
test_attempt(
expected_delay => -1,
expected_timeout => 5,
);
};
subtest "attr: min_adjust_timeout" => sub {
$rt = Algorithm::Backoff::RetryTimeouts->new(
adjust_timeout_factor => 0.75, # just to make this faster
min_adjust_timeout => 0,
# for the unit tests
_start_timestamp => 0,
jitter_factor => 0,
timeout_jitter_factor => 0,
);
$time = 0;
);
# 8: final attempt
test_attempt(
expected_delay => -1,
expected_timeout => 0.001,
);
};
subtest "Jitter factors" => sub {
$rt = Algorithm::Backoff::RetryTimeouts->new(
max_attempts => 0,
consider_actual_delay => 0,
_start_timestamp => 0,
jitter_factor => 0.1,
timeout_jitter_factor => 0.1,
);
# Calculate an average of 1000 hits
my @timeouts;
cmp_ok($avg_timeout, '>=', 24.5, 'Avg timeout within norms (>=)');
cmp_ok($avg_timeout, '<=', 25.5, 'Avg timeout within norms (<=)');
cmp_ok($min_timeout, '<=', 23 , 'Min timeout within norms (<=)');
cmp_ok($max_timeout, '>=', 27 , 'Max timeout within norms (>=)');
cmp_ok($avg_delay, '>=', 1.3, 'Avg delay within norms (>=)');
cmp_ok($avg_delay, '<=', 1.5, 'Avg delay within norms (<=)');
cmp_ok($min_delay, '<=', 1.3, 'Min delay within norms (<=)');
cmp_ok($max_delay, '>=', 1.5, 'Max delay within norms (>=)');
note "AVG: Timeout: $avg_timeout; Delay: $avg_delay";
note "MIN: Timeout: $min_timeout; Delay: $min_delay";
note "MAX: Timeout: $max_timeout; Delay: $max_delay";
};
done_testing;
sub test_attempt {
my (%args) = @_;
# Progress the timestamp
$time += $rt->delay;
$time += $args{attempt_time} // $rt->timeout;
round($delay),
$expected_delay,
"Expected delay: $expected_delay",
);
is(
round($timeout),
$expected_timeout,
"Expected timeout: $expected_timeout",
);
is($delay, $rt->delay, 'Delay method matches return') unless $delay == -1;
is($timeout, $rt->timeout, 'Timeout method matches return');
}
sub round { sprintf("%.3f", shift) + 0; }
( run in 0.313 second using v1.01-cache-2.11-cpan-4d50c553e7e )