mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-20 02:49:49 +01:00
lagchecker: include elapsed time from last ping sent in average if no pong yet received
This commit is contained in:
parent
44ba3001cb
commit
60ad02c9af
@ -47,6 +47,7 @@ sub initialize {
|
||||
$self->{lag_average} = undef; # average of entries in lag history, in seconds
|
||||
$self->{lag_string} = undef; # string representation of lag history and lag average
|
||||
$self->{lag_history} = []; # history of previous PING/PONG timings
|
||||
$self->{pong_received} = undef; # tracks pong replies; undef if no ping sent; 0 if ping sent but no pong reply yet; 1 if ping/pong completed
|
||||
|
||||
$pbot->timer->register(sub { $self->send_ping }, $self->{LAG_HISTORY_INTERVAL});
|
||||
|
||||
@ -59,13 +60,15 @@ sub send_ping {
|
||||
return unless defined $self->{pbot}->conn;
|
||||
|
||||
$self->{ping_send_time} = [gettimeofday];
|
||||
$self->{pong_received} = 0;
|
||||
$self->{pbot}->conn->sl("PING :lagcheck");
|
||||
# $self->{pbot}->logger->log("sent lagcheck PING\n");
|
||||
}
|
||||
|
||||
sub on_pong {
|
||||
my $self = shift;
|
||||
|
||||
$self->{pong_received} = 1;
|
||||
|
||||
my $elapsed = tv_interval($self->{ping_send_time});
|
||||
push @{ $self->{lag_history} }, [ $self->{ping_send_time}[0], $elapsed ];
|
||||
|
||||
@ -96,6 +99,19 @@ sub on_pong {
|
||||
sub lagging {
|
||||
my $self = shift;
|
||||
|
||||
if(defined $self->{pong_received} and $self->{pong_received} == 0) {
|
||||
# a ping has been sent (pong_received is not undef) and no pong has been received yet
|
||||
my $elapsed = tv_interval($self->{ping_send_time});
|
||||
my $lag_total = $elapsed;
|
||||
my $len = @{ $self->{lag_history} };
|
||||
foreach my $entry (@{ $self->{lag_history} }) {
|
||||
my ($send_time, $lag_result) = @{ $entry };
|
||||
$lag_total += $lag_result;
|
||||
}
|
||||
my $average = $lag_total / ($len + 1);
|
||||
return $average >= $self->{LAG_THRESHOLD};
|
||||
}
|
||||
|
||||
return 0 if not defined $self->{lag_average};
|
||||
return $self->{lag_average} >= $self->{LAG_THRESHOLD};
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 326,
|
||||
BUILD_REVISION => 327,
|
||||
BUILD_DATE => "2011-12-11",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user