about summary refs log tree commit homepage
path: root/lib/PublicInbox/NNTP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-04-25 07:51:26 +0000
committerEric Wong <e@80x24.org>2016-04-25 07:53:45 +0000
commit0d02fc0c2441266e5cc64fc92063fcb04bd13bbf (patch)
tree58ee35dd46c3c0f0da29be97985d08ae4f829b19 /lib/PublicInbox/NNTP.pm
parentf55f774e9f2e32267ec5e7ab3647362c4bdaaad9 (diff)
downloadpublic-inbox-0d02fc0c2441266e5cc64fc92063fcb04bd13bbf.tar.gz
Danga::Socket timers are not cheap, so avoid creating up
to 3 timers per-newsgroup by batching resource weakening.
This lets us reduce resource consumption for scheduing
additional resource consumption reduction :)
Diffstat (limited to 'lib/PublicInbox/NNTP.pm')
-rw-r--r--lib/PublicInbox/NNTP.pm19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index c715e8f7..e143d15c 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -38,6 +38,8 @@ my %DISABLED; # = map { $_ => 1 } qw(xover list_overview_fmt newnews xhdr);
 my $EXPMAP; # fd -> [ idle_time, $self ]
 my $EXPTIMER;
 our $EXPTIME = 180; # 3 minutes
+my $WEAKEN = {}; # string(nntpd) -> nntpd
+my $WEAKTIMER;
 
 sub update_idle_time ($) {
         my ($self) = @_;
@@ -46,6 +48,16 @@ sub update_idle_time ($) {
         defined $tmp and $EXPMAP->{$tmp} = [ now(), $self ];
 }
 
+# reduce FD pressure by closing some "git cat-file --batch" processes
+# and unused FDs for msgmap and Xapian indices
+sub weaken_groups () {
+        $WEAKTIMER = undef;
+        foreach my $nntpd (values %$WEAKEN) {
+                $_->weaken_all foreach (@{$nntpd->{grouplist}});
+        }
+        $WEAKEN = {};
+}
+
 sub expire_old () {
         my $now = now();
         my $exp = $EXPTIME;
@@ -69,11 +81,15 @@ sub expire_old () {
                 $next -= $now;
                 $next = 0 if $next < 0;
                 $EXPTIMER = Danga::Socket->AddTimer($next, *expire_old);
+                weaken_groups();
         } else {
                 $EXPTIMER = undef;
-                # noop to kick outselves out of the loop so descriptors
+                # noop to kick outselves out of the loop ASAP so descriptors
                 # really get closed
                 Danga::Socket->AddTimer(0, sub {});
+
+                # grace period for reaping resources
+                $WEAKTIMER ||= Danga::Socket->AddTimer(30, *weaken_groups);
         }
 }
 
@@ -87,6 +103,7 @@ sub new ($$$) {
         $self->{rbuf} = '';
         $self->watch_read(1);
         update_idle_time($self);
+        $WEAKEN->{"$nntpd"} = $nntpd;
         $EXPTIMER ||= Danga::Socket->AddTimer($EXPTIME, *expire_old);
         $self;
 }