Re: Suppressing useless wakeups in walreceiver - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: Suppressing useless wakeups in walreceiver
Date
Msg-id CA+hUKGKw=+=TZ7xzVRQTNfDy5N_uwW_qWhOHDPHyiAkTQAYUug@mail.gmail.com
Whole thread Raw
In response to Re: Suppressing useless wakeups in walreceiver  (Nathan Bossart <nathandbossart@gmail.com>)
Responses Re: Suppressing useless wakeups in walreceiver
List pgsql-hackers
On Mon, Nov 14, 2022 at 1:05 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
> Yeah, I'm able to sort-of reproduce the problem by sending fewer replies,
> but it's not clear to me why that's the problem.  AFAICT all of the code
> paths that write/flush are careful to send a reply shortly afterward, which
> should keep writePtr/flushPtr updated.

Ahh, I think I might have it.  In the old coding, sendTime starts out
as 0, which I think caused it to send its first reply message after
the first 100ms sleep, and only after that fall into a cadence of
wal_receiver_status_interval (10s) while idle.  Our new coding won't
send its first reply until start time + wal_receiver_status_interval.
If I have that right, think we can get back to the previous behaviour
by explicitly setting the first message time, like:

@@ -433,6 +433,9 @@ WalReceiverMain(void)
            for (int i = 0; i < NUM_WALRCV_WAKEUPS; ++i)
                WalRcvComputeNextWakeup(i, now);

+           /* XXX start with a reply after 100ms */
+           wakeup[WALRCV_WAKEUP_REPLY] = now + 100000;
+
            /* Loop until end-of-streaming or error */

Obviously that's bogus and racy (it races with wait_for_catchup, and
it's slow, actually both sides are not great and really should be
event-driven, in later work)...



pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: Bitmapsets as Nodes
Next
From: John Naylor
Date:
Subject: Re: Add palloc_aligned() to allow arbitrary power of 2 memory alignment