user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 0/4] Danga::Socket bundling cleanups
  2019-05-05  0:52  7% [PATCH 0/4] bundle Danga::Socket and Sys::Syscall Eric Wong
  2019-05-05  0:52  7% ` [PATCH 2/4] listener: use EPOLLEXCLUSIVE for listen sockets Eric Wong
@ 2019-05-08 19:18  7% ` Eric Wong
  1 sibling, 0 replies; 3+ results
From: Eric Wong @ 2019-05-08 19:18 UTC (permalink / raw)
  To: meta

Dropping some unused stuff, and a bugfix for an error path we never hit.
(all bugfixes are queued for the future maintainer via
 bug-Danga-Socket@rt.cpan.org )

Eric Wong (4):
  build: do not manify DS and Syscall pods
  syscall: drop readahead wrapper
  DS: drop unused "_undef" sub
  DS: epoll: fix misordered EPOLL_CTL_DEL call

 Makefile.PL                | 10 ++++++++++
 lib/PublicInbox/DS.pm      |  9 +--------
 lib/PublicInbox/Syscall.pm | 14 --------------
 3 files changed, 11 insertions(+), 22 deletions(-)

The "danga-bundle" is up to 10 patches, now; and dogfooded
on public-inbox.org for several days without problems.
Will merge to "master" soon:

      bundle Danga::Socket and Sys::Syscall
      listener: use EPOLLEXCLUSIVE for listen sockets
      DS: remove unused fields and functions
      DS: drop profiling support
      DS: workaround IO::Kqueue EINTR (mis-)handling
      DS: handle EINTR in IO::Poll path, too
      build: do not manify DS and Syscall pods
      syscall: drop readahead wrapper
      DS: drop unused "_undef" sub
      DS: epoll: fix misordered EPOLL_CTL_DEL call

^ permalink raw reply	[relevance 7%]

* [PATCH 2/4] listener: use EPOLLEXCLUSIVE for listen sockets
  2019-05-05  0:52  7% [PATCH 0/4] bundle Danga::Socket and Sys::Syscall Eric Wong
@ 2019-05-05  0:52  7% ` Eric Wong
  2019-05-08 19:18  7% ` [PATCH 0/4] Danga::Socket bundling cleanups Eric Wong
  1 sibling, 0 replies; 3+ results
From: Eric Wong @ 2019-05-05  0:52 UTC (permalink / raw)
  To: meta

Since our listen sockets are non-blocking and we may run
multiple httpd|nntpd processes; we need a way to avoid
thundering herds when there are multiple httpd|nntpd worker
processes.

EPOLLEXCLUSIVE was added just for that in Linux 4.5
---
 TODO                        |  3 ---
 lib/PublicInbox/DS.pm       | 22 ++++++++++++++++------
 lib/PublicInbox/Listener.pm |  2 +-
 lib/PublicInbox/Syscall.pm  |  7 +++++--
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/TODO b/TODO
index 372f733..ac255b8 100644
--- a/TODO
+++ b/TODO
@@ -56,9 +56,6 @@ all need to be considered for everything we introduce)
   ugh... https://rt.cpan.org/Ticket/Display.html?id=116615
   (IO::KQueue is broken with Danga::Socket / PublicInbox::DS)
 
-* EPOLLEXCLUSIVE for listen socket fairness across -httpd/nntpd
-  worker processes.
-
 * improve documentation
 
 * linkify thread skeletons better
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 543d3fd..3ccc275 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -78,6 +78,8 @@ our (
      @Timers,                    # timers
      );
 
+# this may be set to zero with old kernels
+our $EPOLLEXCLUSIVE = EPOLLEXCLUSIVE;
 Reset();
 
 #####################################################################
@@ -666,11 +668,9 @@ This is normally (always?) called from your subclass via:
 
 =cut
 sub new {
-    my PublicInbox::DS $self = shift;
+    my ($self, $sock, $exclusive) = @_;
     $self = fields::new($self) unless ref $self;
 
-    my $sock = shift;
-
     $self->{sock}        = $sock;
     my $fd = fileno($sock);
 
@@ -685,13 +685,23 @@ sub new {
     $self->{corked} = 0;
     $self->{read_push_back} = [];
 
-    $self->{event_watch} = POLLERR|POLLHUP|POLLNVAL;
+    my $ev = $self->{event_watch} = POLLERR|POLLHUP|POLLNVAL;
 
     _InitPoller();
 
     if ($HaveEpoll) {
-        epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $self->{event_watch})
-            and die "couldn't add epoll watch for $fd\n";
+        if ($exclusive) {
+            $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP|$EPOLLEXCLUSIVE;
+        }
+retry:
+        if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $ev)) {
+            if ($!{EINVAL} && ($ev & $EPOLLEXCLUSIVE)) {
+                $EPOLLEXCLUSIVE = 0; # old kernel
+                $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP;
+                goto retry;
+            }
+            die "couldn't add epoll watch for $fd: $!\n";
+        }
     }
     elsif ($HaveKQueue) {
         # Add them to the queue but disabled for now
diff --git a/lib/PublicInbox/Listener.pm b/lib/PublicInbox/Listener.pm
index d1f0d2e..a75a6fd 100644
--- a/lib/PublicInbox/Listener.pm
+++ b/lib/PublicInbox/Listener.pm
@@ -17,7 +17,7 @@ sub new ($$$) {
 	listen($s, 1024);
 	IO::Handle::blocking($s, 0);
 	my $self = fields::new($class);
-	$self->SUPER::new($s); # calls epoll_create for the first socket
+	$self->SUPER::new($s, 1); # calls epoll_create for the first socket
 	$self->watch_read(1);
 	$self->{post_accept} = $cb;
 	$self
diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index cf70045..9194364 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -23,10 +23,12 @@ $VERSION     = "0.25";
 @ISA         = qw(Exporter);
 @EXPORT_OK   = qw(sendfile epoll_ctl epoll_create epoll_wait
                   EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP EPOLLRDBAND
-                  EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD);
+                  EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
+                  EPOLLEXCLUSIVE);
 %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
                              EPOLLIN EPOLLOUT EPOLLERR EPOLLHUP EPOLLRDBAND
-                             EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD)],
+                             EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
+                             EPOLLEXCLUSIVE)],
                 sendfile => [qw(sendfile)],
                 );
 
@@ -35,6 +37,7 @@ use constant EPOLLOUT      => 4;
 use constant EPOLLERR      => 8;
 use constant EPOLLHUP      => 16;
 use constant EPOLLRDBAND   => 128;
+use constant EPOLLEXCLUSIVE => (1 << 28);
 use constant EPOLL_CTL_ADD => 1;
 use constant EPOLL_CTL_DEL => 2;
 use constant EPOLL_CTL_MOD => 3;
-- 
EW


^ permalink raw reply	[relevance 7%]

* [PATCH 0/4] bundle Danga::Socket and Sys::Syscall
@ 2019-05-05  0:52  7% Eric Wong
  2019-05-05  0:52  7% ` [PATCH 2/4] listener: use EPOLLEXCLUSIVE for listen sockets Eric Wong
  2019-05-08 19:18  7% ` [PATCH 0/4] Danga::Socket bundling cleanups Eric Wong
  0 siblings, 2 replies; 3+ results
From: Eric Wong @ 2019-05-05  0:52 UTC (permalink / raw)
  To: meta

This is probably our rarest and most esoteric dependencies
at the moment, so bundle them, add some features, and drop
unused ones.  It'll also give me an excuse to play with more
recent Linux kernel developments :>   More on this in [1/4]

Eric Wong (4):
  bundle Danga::Socket and Sys::Syscall
  listener: use EPOLLEXCLUSIVE for listen sockets
  DS: remove unused fields and functions
  DS: drop profiling support

 INSTALL                           |    4 -
 MANIFEST                          |    2 +
 TODO                              |    5 +-
 lib/PublicInbox/DS.pm             | 1051 +++++++++++++++++++++++++++++
 lib/PublicInbox/Daemon.pm         |    8 +-
 lib/PublicInbox/EvCleanup.pm      |   12 +-
 lib/PublicInbox/GitHTTPBackend.pm |    2 +-
 lib/PublicInbox/HTTP.pm           |   12 +-
 lib/PublicInbox/HTTPD/Async.pm    |    4 +-
 lib/PublicInbox/Listener.pm       |    4 +-
 lib/PublicInbox/NNTP.pm           |    6 +-
 lib/PublicInbox/ParentPipe.pm     |    2 +-
 lib/PublicInbox/Qspawn.pm         |    4 +-
 lib/PublicInbox/Syscall.pm        |  329 +++++++++
 t/git-http-backend.t              |    2 +-
 t/httpd-corner.t                  |    2 +-
 t/httpd-unix.t                    |    2 +-
 t/httpd.t                         |    2 +-
 t/nntp.t                          |    2 +-
 t/nntpd.t                         |    2 +-
 t/v2mirror.t                      |    2 +-
 t/v2writable.t                    |    4 +-
 22 files changed, 1419 insertions(+), 44 deletions(-)
 create mode 100644 lib/PublicInbox/DS.pm
 create mode 100644 lib/PublicInbox/Syscall.pm

-- 
EW


^ permalink raw reply	[relevance 7%]

Results 1-3 of 3 | reverse | sort options + mbox downloads above
-- links below jump to the message on this page --
2019-05-05  0:52  7% [PATCH 0/4] bundle Danga::Socket and Sys::Syscall Eric Wong
2019-05-05  0:52  7% ` [PATCH 2/4] listener: use EPOLLEXCLUSIVE for listen sockets Eric Wong
2019-05-08 19:18  7% ` [PATCH 0/4] Danga::Socket bundling cleanups Eric Wong

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).