diff options
author | Eric Wong <e@80x24.org> | 2016-05-24 03:41:51 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-24 04:12:03 +0000 |
commit | 74bbc3da398d00ba12e9294e360ad177ab2061ed (patch) | |
tree | 964f723b1072e848c4db177ab43ba5461c657e89 /lib/PublicInbox/HTTP.pm | |
parent | e330b2eec13ebda99a7e2981375dee4fe397f14a (diff) | |
download | public-inbox-74bbc3da398d00ba12e9294e360ad177ab2061ed.tar.gz |
Standardize the code we have in place to avoid creating too many timer objects. We do not need exact timers for things that don't need to be run ASAP, so we can play things fast and loose to avoid wasting power with unnecessary wakeups. We only need two classes of timers: * asap - run this on the next loop tick, after operating on @Danga::Socket::ToClose to close remaining sockets * later - run at some point in the future. It could be as soon as immediately (like "asap"), and as late as 60s into the future. In the future, we support an "emergency" switch to fire "later" timers immediately.
Diffstat (limited to 'lib/PublicInbox/HTTP.pm')
-rw-r--r-- | lib/PublicInbox/HTTP.pm | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 104a2132..00c9a044 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -26,13 +26,22 @@ use constant { # FIXME: duplicated code with NNTP.pm my $WEAKEN = {}; # string(inbox) -> inbox -my $WEAKTIMER; +my $weakt; sub weaken_task () { - $WEAKTIMER = undef; + $weakt = undef; $_->weaken_all for values %$WEAKEN; $WEAKEN = {}; } +my $pipelineq = []; +my $pipet; +sub process_pipelineq () { + my $q = $pipelineq; + $pipet = undef; + $pipelineq = []; + rbuf_process($_) foreach @$q; +} + # 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... @@ -234,7 +243,7 @@ sub response_write { if (my $obj = $env->{'pi-httpd.inbox'}) { # grace period for reaping resources $WEAKEN->{"$obj"} = $obj; - $WEAKTIMER ||= Danga::Socket->AddTimer(60, *weaken_task); + $weakt ||= PublicInbox::EvCleanup::later(*weaken_task); } $self->{env} = undef; }; @@ -281,15 +290,6 @@ sub more ($$) { $self->write($_[1]); } -my $pipelineq = []; -my $next_tick; -sub process_pipelineq () { - $next_tick = undef; - my $q = $pipelineq; - $pipelineq = []; - rbuf_process($_) foreach @$q; -} - # overrides existing Danga::Socket method sub event_write { my ($self) = @_; @@ -300,7 +300,7 @@ sub event_write { $self->watch_read(1); } else { # avoid recursion for pipelined requests push @$pipelineq, $self; - $next_tick ||= Danga::Socket->AddTimer(0, *process_pipelineq); + $pipet ||= PublicInbox::EvCleanup::asap(*process_pipelineq); } } |