From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.8 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RP_MATCHES_RCVD,URIBL_BLOCKED shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3B6F61FA7A for ; Tue, 17 May 2016 08:30:01 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] http: release resources when idle Date: Tue, 17 May 2016 08:30:01 +0000 Message-Id: <20160517083001.17275-1-e@80x24.org> List-Id: 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 | 14 ++++++++++++++ lib/PublicInbox/WWW.pm | 2 ++ 2 files changed, 16 insertions(+) diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index bbcb089..1ef3fb3 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -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; }; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 95288a7..465dcb2 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -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;