From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5B1452014C for ; Fri, 25 Sep 2015 02:28:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 8/8] nntp: avoid signals for long responses Date: Fri, 25 Sep 2015 02:27:57 +0000 Message-Id: <20150925022757.6915-9-e@80x24.org> In-Reply-To: <20150925022757.6915-1-e@80x24.org> References: <20150925022757.6915-1-e@80x24.org> List-Id: Using a signal-based timer can hurt throughput on a machine that's overloaded. Ensure there's always forward progress and reduce the number of syscalls we make, too. --- lib/PublicInbox/NNTP.pm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 3490a09..95aa4af 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -11,7 +11,7 @@ use PublicInbox::MID qw(mid2path); use Email::MIME; use Data::Dumper qw(Dumper); use POSIX qw(strftime); -use Time::HiRes qw(clock_gettime ualarm CLOCK_MONOTONIC); +use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC); use constant { r501 => '501 command syntax error', r221 => '221 Header follows', @@ -502,16 +502,13 @@ sub long_response ($$$$) { $self->{long_res} = sub { # limit our own running time for fairness with other # clients and to avoid buffering too much: - my $yield; - local $SIG{ALRM} = sub { $yield = 1 }; - ualarm(100000); + my $lim = 100; my $err; do { eval { $cb->(\$beg) }; } until (($err = $@) || $self->{closed} || - ++$beg > $end || $yield || $self->{write_buf_size}); - ualarm(0); + ++$beg > $end || !--$lim || $self->{write_buf_size}); if ($err || $self->{closed}) { $self->{long_res} = undef; @@ -527,7 +524,7 @@ sub long_response ($$$$) { } else { $self->watch_read(1); } - } elsif ($yield || $self->{write_buf_size}) { + } elsif (!$lim || $self->{write_buf_size}) { # no recursion, schedule another call ASAP # but only after all pending writes are done Danga::Socket->AddTimer(0, sub { -- EW