Re: Suppressing useless wakeups in walreceiver

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Suppressing useless wakeups in walreceiver
Date: 2022-10-11 00:50:59
Message-ID: 20221011005059.GA1277590@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Oct 10, 2022 at 11:10:14AM -0700, Nathan Bossart wrote:
> On Mon, Oct 10, 2022 at 10:51:14AM -0700, Nathan Bossart wrote:
>>> + /* Find the soonest wakeup time, to limit our nap. */
>>> + nextWakeup = INT64_MAX;
>>> + for (int i = 0; i < NUM_WALRCV_WAKEUPS; ++i)
>>> + nextWakeup = Min(state.wakeup[i], nextWakeup);
>>> + nap = Max(0, (nextWakeup - now + 999) / 1000);
> Hm. We should probably be more cautious here since nextWakeup is an int64
> and nap is an int. My guess is that we should just set nap to -1 if
> nextWakeup > INT_MAX.

Here's an attempt at fixing that. I ended up just changing "nap" to an
int64 and then ensuring it's no larger than INT_MAX in the call to
WaitLatchOrSocket(). IIUC we can't use -1 here because WL_TIMEOUT is set.

Nathan Bossart
Amazon Web Services:

Attachment Content-Type Size
v6-0001-Move-WAL-receivers-non-shared-state-to-a-new-stru.patch text/x-diff 11.0 KB
v6-0002-Suppress-useless-wakeups-in-walreceiver.patch text/x-diff 13.7 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2022-10-11 01:31:26 Re: Suppressing useless wakeups in walreceiver
Previous Message Peter Geoghegan 2022-10-11 00:37:46 Re: autovacuum_freeze_max_age reloption seems broken