| 1 | package Algorithm::Backoff::MIMD; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use parent qw(Algorithm::Backoff); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 9 | 2 | our $DATE = '2024-02-24'; # DATE | |||||||||
| 10 | 2 | our $DIST = 'Algorithm-Backoff'; # DIST | |||||||||
| 11 | 2 | our $VERSION = '0.010'; # VERSION | |||||||||
| 12 | |||||||||||
| 13 | 2 | our %SPEC; | |||||||||
| 14 | |||||||||||
| 15 | $SPEC{new} = { | ||||||||||
| 16 | 2 | v => 1.1, | |||||||||
| 17 | is_class_meth => 1, | ||||||||||
| 18 | is_func => 0, | ||||||||||
| 19 | args => { | ||||||||||
| 20 | %Algorithm::Backoff::attr_consider_actual_delay, | ||||||||||
| 21 | %Algorithm::Backoff::attr_max_actual_duration, | ||||||||||
| 22 | %Algorithm::Backoff::attr_max_attempts, | ||||||||||
| 23 | %Algorithm::Backoff::attr_jitter_factor, | ||||||||||
| 24 | %Algorithm::Backoff::attr_max_delay, | ||||||||||
| 25 | %Algorithm::Backoff::attr_min_delay, | ||||||||||
| 26 | %Algorithm::Backoff::attr_initial_delay, | ||||||||||
| 27 | %Algorithm::Backoff::attr_delay_multiple_on_failure, | ||||||||||
| 28 | %Algorithm::Backoff::attr_delay_multiple_on_success, | ||||||||||
| 29 | }, | ||||||||||
| 30 | result_naked => 1, | ||||||||||
| 31 | result => { | ||||||||||
| 32 | schema => 'obj*', | ||||||||||
| 33 | }, | ||||||||||
| 34 | }; | ||||||||||
| 35 | |||||||||||
| 36 | 5 | ▶ | sub _success { | ||||||||
|
Subroutine
_success: called CC=2 SCAR=7.4
| |||||||||||
| 37 | 5 | my ($self, $timestamp) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 5 | ▶ | unless (defined $self->{_prev_delay}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | return $self->{_prev_delay} = $self->{initial_delay}; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 5 | my $delay = $self->{_prev_delay} * $self->{delay_multiple_on_success}; | |||||||||
| 44 | |||||||||||
| 45 | 5 | $delay; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 5 | ▶ | sub _failure { | ||||||||
|
Subroutine
_failure: called CC=2 SCAR=6.9
| |||||||||||
| 49 | 5 | my ($self, $timestamp) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 5 | ▶ | unless (defined $self->{_prev_delay}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 1 | return $self->{_prev_delay} = $self->{initial_delay}; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 4 | my $delay = $self->{_prev_delay} * $self->{delay_multiple_on_failure}; | |||||||||
| 56 | |||||||||||
| 57 | 4 | $delay; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 2 | 1; | |||||||||
| 61 | # ABSTRACT: Multiplicative Increment, Multiplicative Decrement (MIMD) backoff | ||||||||||
| 62 | |||||||||||
| 63 | __END__ | ||||||||||