summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2003-06-09 18:57:41 +0000
committerPeter Palfrader <peter@palfrader.org>2003-06-09 18:57:41 +0000
commit229661b45b57798e72c3f5460d437f046c9a172a (patch)
tree7d4ded62f39aa9d50dec7fbcaf6e39692f4a7e86
parent580d29c3743df13f983a6965754be1ac88c075a6 (diff)
Optimized CPU usage of chainpinging
-rw-r--r--Echolot/Chain.pm80
-rw-r--r--NEWS1
2 files changed, 38 insertions, 43 deletions
diff --git a/Echolot/Chain.pm b/Echolot/Chain.pm
index b695301..3e42be5 100644
--- a/Echolot/Chain.pm
+++ b/Echolot/Chain.pm
@@ -1,7 +1,7 @@
package Echolot::Chain;
# (c) 2002 Peter Palfrader <peter@palfrader.org>
-# $Id: Chain.pm,v 1.16 2003/02/22 15:11:27 weasel Exp $
+# $Id: Chain.pm,v 1.17 2003/06/09 18:57:41 weasel Exp $
#
=pod
@@ -106,27 +106,6 @@ sub do_chainping($$$$$$$) {
return 1;
};
-sub remailer_supports_chaintype($$) {
- my ($address, $type) = @_;
-
- my %supports = map { $_ => 1} Echolot::Globals::get()->{'storage'}->get_types($address);
- for my $type (@{Echolot::Config::get()->{'which_chainpings'}->{$type}}) {
- return $type if $supports{$type};
- };
- return 0;
-};
-sub get_latest_key($$) {
- my ($address, $type) = @_;
-
- my $latest = 0;
- my $chosen = undef;
- for my $keyid (Echolot::Globals::get()->{'storage'}->get_keys($address, $type)) {
- my %key = Echolot::Globals::get()->{'storage'}->get_key($address, $type, $keyid);
- $chosen = $keyid, $latest = $key{'last_update'} if $latest < $key{'last_update'};
- };
- return $chosen;
-};
-
sub send_pings($;$$) {
return 1 unless Echolot::Config::get()->{'do_chainpings'};
@@ -150,23 +129,40 @@ sub send_pings($;$$) {
my $session_id_ic = int ($scheduled_for / ($call_intervall * $send_every_n_calls_ic));
my @remailers = Echolot::Globals::get()->{'storage'}->get_remailers();
- for my $rem1 (@remailers) {
- next unless $rem1->{'pingit'};
- my $addr1 = $rem1->{'address'};
-
- next unless (
- $which1 eq 'all' ||
- $which1 eq $addr1 ||
- $which1 eq '');
-
- for my $chaintype (keys %{Echolot::Config::get()->{'which_chainpings'}}) {
- my $type1 = remailer_supports_chaintype($addr1, $chaintype);;
- next unless $type1;
- my $key1 = get_latest_key($addr1, $type1);
-
- for my $rem2 (@remailers) {
- next unless $rem2->{'pingit'};
- my $addr2 = $rem2->{'address'};
+ for my $chaintype (keys %{Echolot::Config::get()->{'which_chainpings'}}) {
+
+ my @thisrems;
+ for my $rem (@remailers) {
+ next unless $rem->{'pingit'};
+ my $addr = $rem->{'address'};
+ my $type;
+ my %supports = map { $_ => 1 } Echolot::Globals::get()->{'storage'}->get_types($addr);
+ for my $thistype (@{Echolot::Config::get()->{'which_chainpings'}->{$chaintype}}) {
+ $type = $thistype, last if $supports{$chaintype};
+ };
+ next unless $type;
+ my $key;
+ my $latest = 0;
+ for my $keyid (Echolot::Globals::get()->{'storage'}->get_keys($addr, $type)) {
+ my %key = Echolot::Globals::get()->{'storage'}->get_key($addr, $type, $keyid);
+ $key = $keyid, $latest = $key{'last_update'} if $latest < $key{'last_update'};
+ };
+ push @thisrems, { addr => $addr, type => $type, key => $key };
+ };
+
+ for my $rem1 (@thisrems) {
+ my $addr1 = $rem1->{'addr'};
+
+ next unless (
+ $which1 eq 'all' ||
+ $which1 eq $addr1 ||
+ $which1 eq '');
+
+ my $type1 = $rem1->{'type'};
+ my $key1 = $rem1->{'key'};
+
+ for my $rem2 (@thisrems) {
+ my $addr2 = $rem2->{'addr'};
next if $rem1 eq $rem2 && (! ($which1 eq $addr2 && $which2 eq $addr2));
next unless (
@@ -174,10 +170,8 @@ sub send_pings($;$$) {
$which2 eq $addr2 ||
$which2 eq '');
- my $type2 = remailer_supports_chaintype($addr2, $chaintype);;
- next unless $type2;
- my $key2 = get_latest_key($addr2, $type2);
-
+ my $type2 = $rem2->{'type'};
+ my $key2 = $rem2->{'key'};
my $call_id = Echolot::Tools::makeShortNumHash($addr1.$addr2.$chaintype.$session_id ) % $send_every_n_calls;
my $call_id_ic = Echolot::Tools::makeShortNumHash($addr1.$addr2.$chaintype.$session_id_ic) % $send_every_n_calls_ic;
diff --git a/NEWS b/NEWS
index 23e6969..90ecae4 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Changes in
use percentiles when calculating a life probability of an outstanding
ping. Also we do not show the mean of latency but the median as
this seems to be 'more correct'.
+ * Optimized chain pinging: takes less CPU.
Changes in version
* Minor documentation fixes suggested by Ryan Lackey.