about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-09-25 02:27:57 +0000
committerEric Wong <e@80x24.org>2015-09-25 02:29:09 +0000
commit79d8bfedcdd27a9163a64593ff9bac4bb2202fbd (patch)
tree956a98a6fba4c150dfe929418a6abf37b6fa9b08 /lib
parent2e500cb8421e73947bc961ee57d8d57efacae394 (diff)
downloadpublic-inbox-79d8bfedcdd27a9163a64593ff9bac4bb2202fbd.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/NNTP.pm11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 3490a098..95aa4af7 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 {