From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] send_cmd: throttle `sleeping on sendmsg' messages
Date: Fri, 29 Nov 2024 23:54:00 +0000 [thread overview]
Message-ID: <20241129235400.138579-3-e@80x24.org> (raw)
In-Reply-To: <20241129235400.138579-1-e@80x24.org>
Emitting a message every 100ms was too much for busy machines.
Throttle it to 1.6s to avoid flooding user terminals by emitting
every 16 sleeps. A power-of-two (16) was chosen for its
optimization potential via bitwise AND. Since perl(1) doesn't
do this optimization, we open code the bitwise AND. I don't
assume an optimizing compiler for Inline::C, either, since I
find working in C far more enjoyable with optimizations off.
---
lib/PublicInbox/CmdIPC4.pm | 3 ++-
lib/PublicInbox/Spawn.pm | 6 ++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/CmdIPC4.pm b/lib/PublicInbox/CmdIPC4.pm
index bdf17a3f..af49f36d 100644
--- a/lib/PublicInbox/CmdIPC4.pm
+++ b/lib/PublicInbox/CmdIPC4.pm
@@ -12,7 +12,8 @@ sub sendmsg_retry ($) {
return 1 if $!{EINTR};
return unless ($!{ENOMEM} || $!{ENOBUFS} || $!{ETOOMANYREFS});
return if $_[0]-- == 0;
- warn "# sleeping on sendmsg: $! ($_[0] tries left)\n";
+ # n.b. `N & (power-of-two - 1)' is a faster `N % power-of-two'
+ warn "# sleeping on sendmsg: $! ($_[0] tries left)\n" if !($_[0] & 15);
select(undef, undef, undef, 0.1);
1;
}
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 1c6cc5be..d818af0f 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -184,8 +184,10 @@ static int sendmsg_retry(long *tries)
case EINTR: PERL_ASYNC_CHECK(); return 1;
case ENOBUFS: case ENOMEM: case ETOOMANYREFS:
if (*tries-- == 0) return 0;
- fprintf(stderr, "# sleeping on sendmsg: %s (%ld tries left)\n",
- strerror(err), *tries);
+ if (!(*tries & 15))
+ fprintf(stderr,
+ "# sleeping on sendmsg: %s (%ld tries left)\n",
+ strerror(err), *tries);
nanosleep(&req, NULL);
PERL_ASYNC_CHECK();
return 1;
next prev parent reply other threads:[~2024-11-29 23:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 23:53 [PATCH 0/2] send_cmd IPC improvements for busy sytems Eric Wong
2024-11-29 23:53 ` [PATCH 1/2] send_cmd: use (practically) infinite retries for writers Eric Wong
2024-11-29 23:54 ` Eric Wong [this message]
2024-11-30 8:26 ` [PATCH 3/2] wqblocked: use per-instance unique timer 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=20241129235400.138579-3-e@80x24.org \
--to=e@80x24.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.
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).