| 1 | package Cassandra::Client::Policy::Throttle::Adaptive; | ||||||||||||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:TVDW'; | |||||||||||||||||||||||||||||||||||||
| 3 | 2 | $Cassandra::Client::Policy::Throttle::Adaptive::VERSION = '0.21'; | |||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use parent 'Cassandra::Client::Policy::Throttle::Default'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Time::HiRes qw/CLOCK_MONOTONIC/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Ref::Util qw/is_blessed_ref/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Cassandra::Client::Error::ClientThrottlingError; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my ($class, %args)= @_; | |||||||||||||||||||||||||||||||||||||
| 14 | return bless { | ||||||||||||||||||||||||||||||||||||||
| 15 | ratio => $args{ratio} || 2, | ||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | time => $args{time} || 120, | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$args{'ratio'} || 2
$args{'time'} || 120
MC/DC0%0/1
$args{'ratio'} || 2
$args{'ratio'}
MC/DC0%0/1
$args{'time'} || 120
$args{'time'}
Truth table0%0/2
A
A= $args{'ratio'}
Truth table0%0/2
A
A= $args{'time'}
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | window => [], | ||||||||||||||||||||||||||||||||||||||
| 19 | window_success => 0, | ||||||||||||||||||||||||||||||||||||||
| 20 | window_total => 0, | ||||||||||||||||||||||||||||||||||||||
| 21 | }, $class; | ||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub _process_window { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_window: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $now= Time::HiRes::clock_gettime(CLOCK_MONOTONIC); | |||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | while (@{$self->{window}} && $self->{window}[0][0] < $now) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@{$self->{"window"};} and $self->{"window"}[0][0] < $now
MC/DC0%0/2
@{$self->{"window"};} and $self->{"window"}[0][0] < $now
@{$self->{"window"};}
$self->{"window"}[0][0] < $now
Truth table0%0/3
A and B
A= @{$self->{"window"};}B= $self->{"window"}[0][0] < $now
| |||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $entry= shift @{$self->{window}}; | |||||||||||||||||||||||||||||||||||||
| 29 | 0 | $self->{window_total}--; | |||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $self->{window_success}-- if $entry->[1]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub should_fail { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
should_fail: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($self)= @_; | |||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->_process_window; | |||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $fail= ( rand() < (($self->{window_total} - ($self->{ratio} * $self->{window_success})) / ($self->{window_total} + 1)) ); | |||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return unless $fail; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->count(undef, 1); | |||||||||||||||||||||||||||||||||||||
| 43 | 0 | return Cassandra::Client::Error::ClientThrottlingError->new; | |||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub count { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
count: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($self, $error, $force_error)= @_; | |||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return if is_blessed_ref($error) && $error->isa('Cassandra::Client::Error::ClientThrottlingError'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
is_blessed_ref($error) and $error->isa("Cassandra::Client::Error::ClientThrottlingError")
MC/DC0%0/2
is_blessed_ref($error) and $error->isa("Cassandra::Client::Error::ClientThrottlingError")
is_blessed_ref($error)
$error->isa("Cassandra::Client::Error::ClientThrottlingError")
Truth table0%0/3
A and B
A= is_blessed_ref($error)B= $error->isa("Cassandra::Client::Error::ClientThrottlingError")
| |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->{window_total}++; | |||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $success= !(is_blessed_ref($error) && $error->is_timeout) && !$force_error; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
is_blessed_ref($error) && $error->is_timeout || $force_error
is_blessed_ref($error) and $error->is_timeout
MC/DC0%0/3
is_blessed_ref($error) && $error->is_timeout || $force_error
is_blessed_ref($error)
$error->is_timeout
$force_error
Truth table0%0/5
A and B || C
A= is_blessed_ref($error)B= $error->is_timeoutC= $force_error
| |||||||||||||||||||||||||||||||||||||||
| 53 | 0 | push @{$self->{window}}, [ Time::HiRes::clock_gettime(CLOCK_MONOTONIC)+$self->{time}, $success ]; | |||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $self->{window_success}++ if $success; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 2 | 1; | |||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||||||||||||