| From: | Arseniy Mukhin <arseniy(dot)mukhin(dot)dev(at)gmail(dot)com> |
|---|---|
| To: | Joel Jacobson <joel(at)compiler(dot)org> |
| Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Optimize LISTEN/NOTIFY |
| Date: | 2025-11-12 16:57:51 |
| Message-ID: | CAE7r3MJyitsHSd9A-y42Cmzs5gmG=zJH2pqMytSVzmzF4e_K9A@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Tue, Nov 11, 2025 at 7:35 PM Joel Jacobson <joel(at)compiler(dot)org> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bertrand Drouvot | 2025-11-12 17:03:55 | Re: relfilenode statistics |
| Previous Message | Jacob Champion | 2025-11-12 16:35:58 | Re: CURL_IGNORE_DEPRECATION |