]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wqworker: favor level-triggered epoll for fairness
authorEric Wong <e@80x24.org>
Sat, 16 Oct 2021 09:29:50 +0000 (09:29 +0000)
committerEric Wong <e@80x24.org>
Sat, 16 Oct 2021 10:37:06 +0000 (10:37 +0000)
Sigfd->event_step needs priority over WQWorkers (and everything
else).  Do that by running once per event_loop iteration rather
than looping inside event_step.  This lowers throughput since it
requires more syscalls, but that's the price of fairness.

lib/PublicInbox/WQWorker.pm

index 48b901bb139feec7d4abd9ff6f95ccb149cdc026..950bd17052a569b7e6792f875791d801525d821d 100644 (file)
@@ -6,7 +6,7 @@ package PublicInbox::WQWorker;
 use strict;
 use v5.10.1;
 use parent qw(PublicInbox::DS);
-use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE EPOLLET);
+use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE);
 use Errno qw(EAGAIN ECONNRESET);
 use IO::Handle (); # blocking
 
@@ -14,19 +14,19 @@ sub new {
        my ($cls, $wq, $sock) = @_;
        $sock->blocking(0);
        my $self = bless { sock => $sock, wq => $wq }, $cls;
-       $self->SUPER::new($sock, EPOLLEXCLUSIVE|EPOLLIN|EPOLLET);
+       $self->SUPER::new($sock, EPOLLEXCLUSIVE|EPOLLIN);
        $self;
 }
 
 sub event_step {
        my ($self) = @_;
-       my $n;
-       do {
-               $n = $self->{wq}->recv_and_run($self->{sock});
-       } while ($n);
-       return if !defined($n) && $! == EAGAIN; # likely
-       warn "wq worker error: $!\n" if !defined($n) && $! != ECONNRESET;
-       $self->{wq}->wq_atexit_child if $self->{sock} == $self->{wq}->{-wq_s2};
+       my $n = $self->{wq}->recv_and_run($self->{sock}) and return;
+       unless (defined $n) {
+               return if $! == EAGAIN;
+               warn "recvmsg: $!" if $! != ECONNRESET;
+       }
+       $self->{sock} == $self->{wq}->{-wq_s2} and
+               $self->{wq}->wq_atexit_child;
        $self->close; # PublicInbox::DS::close
 }