From: Eric Wong <e@80x24.org>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: meta@public-inbox.org
Subject: [PATCH] listener: don't set listen backlog on inherited sockets
Date: Wed, 5 Mar 2025 00:45:36 +0000 [thread overview]
Message-ID: <20250305004536.M405691@dcvr> (raw)
In-Reply-To: <20250304221421.M144167@dcvr>
Eric Wong <e@80x24.org> wrote:
> I wonder if prioritizing certain User-Agents (e.g. curl, w3m,
> anything with non-Anroid "Linux" in it) would be a quick fix in
> haproxy||nginx.
This seems like a long overdue change to allow certain listen
sockets to handle more traffic than others.
---------8<-------
Subject: [PATCH] listener: don't set listen backlog on inherited sockets
By using the listen(2) backlog as-is when inheriting (from
systemd or similar), we can give the sysadmin more control on
controlling overload on a per-listener basis. For systemd
users, this means the `Backlog=' parameter in systemd.socket(5)
can be respected and configured to give certain sockets a
smaller backlog (perhaps combined with with per-listener
`multi-accept' parameter on sockets with the standard (huge)
backlog).
For sockets we create, continue to use INT_MAX and let the
kernel clamp it to whatever system-wide limit there is
(e.g. `net.core.somaxconn' sysctl on Linux).
---
lib/PublicInbox/Daemon.pm | 2 +-
lib/PublicInbox/LEI.pm | 3 ++-
lib/PublicInbox/Listener.pm | 1 -
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 5d93f81f..8fe93acd 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -264,7 +264,7 @@ EOF
die $@ if $@;
%o = (LocalAddr => $l, ReuseAddr => 1, Proto => 'tcp');
}
- $o{Listen} = 1024;
+ $o{Listen} = 2**31 - 1; # kernel will clamp
my $prev = umask 0000;
my $s = eval { $sock_pkg->new(%o) } or
warn "error binding $l: $! ($@)\n";
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 94bac688..0a779c4f 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -9,7 +9,7 @@ package PublicInbox::LEI;
use v5.12;
use parent qw(PublicInbox::DS PublicInbox::LeiExternal
PublicInbox::LeiQuery);
-use autodie qw(bind chdir open pipe socket socketpair syswrite unlink);
+use autodie qw(bind chdir listen open pipe socket socketpair syswrite unlink);
use Getopt::Long ();
use Socket qw(AF_UNIX SOCK_SEQPACKET pack_sockaddr_un);
use Errno qw(EPIPE EAGAIN ECONNREFUSED ENOENT ECONNRESET EINTR);
@@ -1371,6 +1371,7 @@ sub lazy_start {
local (%PATH2CFG, $MDIR2CFGPATH);
local $daemon_pid = $$;
$listener->blocking(0);
+ listen $listener, 2**31 - 1; # kernel will clamp
my $exit_code;
my $pil = PublicInbox::Listener->new($listener, \&accept_dispatch);
local $quit = do {
diff --git a/lib/PublicInbox/Listener.pm b/lib/PublicInbox/Listener.pm
index c83901b2..62475600 100644
--- a/lib/PublicInbox/Listener.pm
+++ b/lib/PublicInbox/Listener.pm
@@ -21,7 +21,6 @@ sub new {
my ($class, $s, $cb, $multi_accept) = @_;
setsockopt($s, SOL_SOCKET, SO_KEEPALIVE, 1);
setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1); # ignore errors on non-TCP
- listen($s, 2**31 - 1); # kernel will clamp
my $self = bless { post_accept => $cb }, $class;
$self->{multi_accept} = $multi_accept //= $MULTI_ACCEPT;
$self->SUPER::new($s, EPOLLIN|EPOLLEXCLUSIVE);
next prev parent reply other threads:[~2025-03-05 0:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 19:44 Gemini protocol view? Konstantin Ryabitsev
2025-03-04 22:14 ` Eric Wong
2025-03-05 0:45 ` Eric Wong [this message]
2025-03-05 16:54 ` [PATCH] listener: don't set listen backlog on inherited sockets Konstantin Ryabitsev
2025-03-07 21:25 ` Gemini protocol view? Eric Wong
2025-03-11 19:26 ` Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250305004536.M405691@dcvr \
--to=e@80x24.org \
--cc=konstantin@linuxfoundation.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public 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).