From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4DE391F4CA for ; Fri, 29 Nov 2024 23:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1732924441; bh=CH5DgITgdEBNOFa04a8ZmHbIbfo2FSW2WqWk7EF6Vu8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CpxxSghT21yLkI3HtFWBc935FinxvPljx9STN+o6fReZ+lkAjSYAZT7E5e/MQLnA3 2gpmQvFbTK+Ve+vWORctoTA3u+F9kcNHwtVyCkyyowpoGfnmTZNMxFS6jiI91H219t GHA9PQhADa2AaaHy3/+8oB/UjQhBm+vTwb2/ieFU= From: Eric Wong 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 Message-ID: <20241129235400.138579-3-e@80x24.org> In-Reply-To: <20241129235400.138579-1-e@80x24.org> References: <20241129235400.138579-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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;