]> Sergey Matveev's repositories - public-inbox.git/commitdiff
http: release resources when idle
authorEric Wong <e@80x24.org>
Tue, 17 May 2016 08:16:47 +0000 (08:16 +0000)
committerEric Wong <e@80x24.org>
Tue, 17 May 2016 08:28:55 +0000 (08:28 +0000)
This lets us release old git processes so unlinked packs
(leftover from repacking) can be released.  This may also
be helpful for Xapian as indices get rebuilt for tuning.

For SQLite (msgmap), the there may be no benefit besides
reducing FD pressure.

Followup changes will unify the Inbox and NewsGroup
classes and allow better code-sharing between NNTP and
HTTP classes (as well as the planned POP3 class).

lib/PublicInbox/HTTP.pm
lib/PublicInbox/WWW.pm

index bbcb0898612c905f4df1094ce8057c4b4547b832..1ef3fb31d8d6f8a61a1482860e33ddf5becc2b65 100644 (file)
@@ -24,6 +24,15 @@ use constant {
        CHUNK_MAX_HDR => 256,
 };
 
+# FIXME: duplicated code with NNTP.pm
+my $WEAKEN = {}; # string(inbox) -> inbox
+my $WEAKTIMER;
+sub weaken_task () {
+       $WEAKTIMER = undef;
+       $_->weaken_all for values %$WEAKEN;
+       $WEAKEN = {};
+}
+
 # Use the same configuration parameter as git since this is primarily
 # a slow-client sponge for git-http-backend
 # TODO: support per-respository http.maxRequestBuffer somehow...
@@ -198,6 +207,11 @@ sub response_write {
                } else {
                        $self->write(sub { $self->close });
                }
+               if (my $obj = $env->{'pi-httpd.inbox'}) {
+                       # grace period for reaping resources
+                       $WEAKEN->{"$obj"} = $obj;
+                       $WEAKTIMER ||= Danga::Socket->AddTimer(60, *weaken_task);
+               }
                $self->{env} = undef;
        };
 
index 95288a7b4d99379224e8ee262dfac154183488c8..465dcb267e184e1404d24792c71bce98d34b1128 100644 (file)
@@ -129,6 +129,8 @@ sub invalid_inbox {
        if (defined $obj) {
                $ctx->{git_dir} = $obj->{mainrepo};
                $ctx->{git} = $obj->git;
+               # for PublicInbox::HTTP::weaken_task:
+               $ctx->{cgi}->{env}->{'pi-httpd.inbox'} = $obj;
                $ctx->{-inbox} = $obj;
                $ctx->{inbox} = $inbox;
                return;