public inbox for [email protected]  
help / color / mirror / Atom feed
From: Arseniy Mukhin <[email protected]>
To: Joel Jacobson <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: Optimize LISTEN/NOTIFY
Date: Wed, 12 Nov 2025 19:57:51 +0300
Message-ID: <CAE7r3MJyitsHSd9A-y42Cmzs5gmG=zJH2pqMytSVzmzF4e_K9A@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAK80=jhmE40KVqQ3ho37MArS7cAED1p9m7uikDxcnDmqdW7t8A@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CA+hUKGLrMGkWDB0cwTa0RqD+AF7O-Ywgck8aVYKwOQnZgYRRug@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAFY6G8dap-bCnAnMG-2Gzew8yv2Vbi9gsx9+yszKMmd57ygfvA@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAE7r3MLivh1sHWF06hrVXkiQbw-KChPcQsh+9CheXprm5vRVMQ@mail.gmail.com>
	<[email protected]>
	<CAE7r3MK-3AOdh1mpZ8hw9h6F_i0D5RMoAy7CttnfCJRpB8GJDA@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAE7r3MJxxycYwDFJdTJ+HmzeNJ_JGKyr4HpT5njN1ouVX56OUg@mail.gmail.com>
	<[email protected]>
	<CAE7r3MJ0VoAJzdLzX0dgfPJpBJxW+wg_pYaCi6mQJi47+qukhg@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

Hi,

On Tue, Nov 11, 2025 at 7:35 PM Joel Jacobson <[email protected]> wrote:
>
> On Sat, Nov 8, 2025, at 16:04, Joel Jacobson wrote:
> > On Sat, Nov 8, 2025, at 13:59, Joel Jacobson wrote:
> >> On Fri, Nov 7, 2025, at 19:59, Joel Jacobson wrote:
> >> This in turn could cause a listening backend to remain behind, if there
> >> would be no more notifies, so it unfortunately seems like we will always
> >> need to signal when a backend isAdvancing, and therefore have no use of
> >> the advancingPos field.
>
> Having thought about this, I don't think this is actually a problem,
> since this isn't any worse than what we currently have in master.
> Listening backends can currently end up stationary behind QUEUE_HEAD, in
> exactly this situation, when they don't read up until QUEUE_HEAD in
> asyncQueueReadAllNotifications. In this case, we currently rely on
> another NOTIFY to wake them up, so v24 wouldn't be any worse.
>
> My apologies for again making the mistake of mixing in robustness
> improvements into this patch. I must keep in mind this is solely an
> optimization patch.
>
> I'm therefore attaching v24 again, but renamed to v26.

Thank you for the new version!

I read direct advancement part of v26, one point about it:

The comment in SignalBackend says:

           * Listening backends that are not advancing and are stationary at
           * a position somewhere in the range we just wrote, can safely be
           * direct advanced to the new queue head, since we know that they
           * are not interested in our messages.
           */

IIUC it's impossible for the listener to stop somewhere in between
queueHeadBeforeWrite and queueHeadAfterWrite. If the listener has
managed to read the first notification from the notifier, it means the
notifier transaction is complete and the listener should stop only
after reading all notifications (so we should always see pos =
queueHeadAfterWrite or further).

So If I haven't missed anything, I think we can use QUEUE_POS_EQUAL as
direct advancement condition:

    if (!QUEUE_BACKEND_IS_ADVANCING(i) && QUEUE_POS_EQUAL(pos,
queueHeadBeforeWrite))
    {
           QUEUE_BACKEND_POS(i) = queueHeadAfterWrite;
    }


Best regards,
Arseniy Mukhin





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Optimize LISTEN/NOTIFY
  In-Reply-To: <CAE7r3MJyitsHSd9A-y42Cmzs5gmG=zJH2pqMytSVzmzF4e_K9A@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox