Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vGo7A-004QDj-Us for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Nov 2025 00:44:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vGmpM-004S7L-Le for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Nov 2025 23:22:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vGmpM-004S7D-Av for pgsql-hackers@lists.postgresql.org; Wed, 05 Nov 2025 23:22:07 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vGmpI-006BzQ-2G for pgsql-hackers@postgresql.org; Wed, 05 Nov 2025 23:22:07 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-29516a36affso3445315ad.3 for ; Wed, 05 Nov 2025 15:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762384922; x=1762989722; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nQWwH9TjjDZS942Ru4OMuT/73hxL+1KHqGxFkopt3dI=; b=lVpmD5AxWNr07vrJjwVadVMTkRAN4lGR55LVQn47zXP7HUhYOy8rnsHtNDEXXSthLY ecV3iRhx+BmexbjwiTuCMMmzrlGKwI0L5JhWz3a0ggrh8iyb9jHqBinfatH9JPhXeWIZ w+yYkMSC0JdzjfRtp+2UPg2WbJcYtEYG9ZuNNUtQUlumIKysNnfCZGCYefTRfMPKDNwZ cDj5Daa8B61QEKeCgP/55JxeLAnOL1L9S/rg66SjNPRh36Tb2oS/jM1Akt1FbiyIc5+h h9K82rtPvufsjTvB8LZBtXg5KrJexkEjwXZUsJGY7kFRjuKSUXkauZ3/NpcMf5OW61sz EbvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762384922; x=1762989722; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nQWwH9TjjDZS942Ru4OMuT/73hxL+1KHqGxFkopt3dI=; b=a3RAu+e7A2EMPBbqkVE1AyogPaw3nBaTP/p7SfNnAvDTYFPeQjKeqfDsZMQc9O1juu ++mL5wYK8r42U7/PEQK9vZv6BoPuhPpVRAPa4DkKY0mCt01JRat/FUqVIJhH9EbFcmD3 ZYDUktFbhoh+6Jw302UPKJwRF40MMuiNi/FuH3IS2MG+j8D4S0+MBVRqnoBCDem8Wztp Piz6uQnoXBIR6//nSyQwxK8Yp99Gnctp0dM3u/AUDCKKKyCYdz4bhNclrxPyIWDRyiF6 KWGtmpSZybZBc/YzOo4pmDWHmxZ3Y4jGglbihBiQnRn08EhmI36Hm4YGjOzZw0uPbHNE EdZg== X-Forwarded-Encrypted: i=1; AJvYcCUkxB68BrIvlLl7oz4ToFA7eQPx3j2RLroigkXPp6TqXtN8VPjTvMnipv+HpCOPO3oNFH28/yJ7yO8Py5y4@postgresql.org X-Gm-Message-State: AOJu0YxLN9svlVsS5wstVL+7jhoLH+4Znu5IhOQE9r0sSRbgZtOHiQSg qEOXE+soU/frbuCLdRF4TQtlWLSTJndGtM+c63mQYA5tJjjrpl+6ioBY X-Gm-Gg: ASbGncsIDKJb3YVP6uPsiJk9PCOv9EPzGpASyEKG7XDRrsGbxV/jatNtJNqh6kHgKNi J/ESH6sD3g229IGhxSZAg3JyExP7s7osSerogtuem/YqVgqRiHln1Y8AawGMSGt7LmH13U9ZceQ pDe7wnpd4rsZin3voCo87PpqMU1G/a9tngIa3dCgSUWCrrdgGNdAjZelNJDwnHIoWlMuVIjxj0W LGc0NS+9z3zVInnUC/Co3RgkwF6pJ0iDIqfZ8dTxvDHlhXZdy9dFW92zbGgyjaaCzBgKOgkBrM2 CDHUvo5eWWBO32sXc/eSUNNitQJ41TzPafHQ2T6b9P+8TdVcqnpxJ16ruDxI1UXAwupm427VUp1 1q0iJDSIDL53LX0F+9X4z4fbHptIfSgR+bl9d/aM1azC/VSlPV4wEaOI/mJi+aJL1yBUZaAM6MN FNY2gQgZqQfP4= X-Google-Smtp-Source: AGHT+IFhOthgoJygu/dWcCrzpZvp4AoF17qpXpifSiciQvh2XezyrzdImeZmJoFmDoWC/6jzQp1nLg== X-Received: by 2002:a17:902:ecd2:b0:295:9a46:a1d0 with SMTP id d9443c01a7336-2962adb95c2mr76269935ad.45.1762384922035; Wed, 05 Nov 2025 15:22:02 -0800 (PST) Received: from smtpclient.apple ([170.178.170.211]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29650c5cae6sm6686015ad.30.2025.11.05.15.21.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Nov 2025 15:22:01 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Optimize LISTEN/NOTIFY From: Chao Li In-Reply-To: Date: Thu, 6 Nov 2025 07:21:17 +0800 Cc: Joel Jacobson , pgsql-hackers Content-Transfer-Encoding: quoted-printable Message-Id: <4605CAD6-69D5-4082-B96C-91FC0DE5399D@gmail.com> References: <6899c044-4a82-49be-8117-e6f669765f7e@app.fastmail.com> <165530.1752362320@sss.pgh.pa.us> <02a7cd37-e2fc-4212-8b19-f8c239c95fb8@app.fastmail.com> <96f00bf1-cc9d-4520-9d02-9e14e7767c88@app.fastmail.com> <30c2aa7d-dd6c-4b68-a2e4-f217a1a34acf@app.fastmail.com> <0b4d402a-9ac2-4aa8-acf8-8231dbe579ea@app.fastmail.com> <3095599.1758644879@sss.pgh.pa.us> <0dc6a2cc-5216-4dc1-9dd2-430cafc6095b@app.fastmail.com> <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> <9186C6D0-F7A9-482A-9183-89E530B57E36@gmail.com> <1073593.1759423179@sss.pgh.pa.us> <4bd5e6c4-6fa7-44bb-869d-59a32a331fa8@app.fastmail.com> <85828f29-e72e-4400-94f3-9a69bc8dc239@app.fastmail.com> <2495353.1759860890@sss.pgh.pa.us> <8aeae418-92a6-4bbd-9c06-9574c79e59f7@app.fastmail.com> <2531672.1759868124@sss.pgh.pa.us> <474efa78-337c-41cd-a73a-f845a0115109@app.fastmail.com> <2749343.1759949176@sss.pgh.pa.us> <8bfca2be-1ec0-4e15-aafb-0b7b661fe936@app.fastmail.com> <9eba307f-f2fb-48f0-9507-2e197f39ef9e@app.fastmail.com> <8c71183a-0d28-4bcf-a806-78446ff95404@app.fastmail.com> <1009807.1760476747@sss.pgh.pa.us> <1F7227F5-C33D-4E2C-8511-33F1468590D0@gmail.com> <0a5a20d3-4621-46b3-b2ab-903f63a20dea@app.fastmail.com> <6F913129-ABEF-4004-AAF3-F22FC34!29AE8@gmail.com> <1547585.1760645808@sss.pgh.pa.us> <14865EB6-0BF4-462B-9072-10BDAC10C052@gmail.com> <0BCA1C2D-B92C-459E-B1A6-6D06BA4C62CF@gmail.com> <55d24cbb-e9ef-491f-a99b-b3dbd7cecdf9@app.fastmail.com> <38574cad-e90d-47b7-a015-753bb6bbc360@app.fastmail.com> <66631FB7-5BEA-4ED5-A694-9AD8B9CCFEE8@gmail.com> <4b7b49a5-5e1a-44a8-93e0-60457d15cb1d@app.fastmail.com> <82DEA2B6-6FC5-4A79-BDE3-1FD72F104A6E@gmail.com> <38de1036-d8cf-420c-b845-edb5a946b191@app.fastmail.com> <87E40BF8-8877-4DBD-9040-99AF8A4E6358@gmail.com> <7556f0d4-03fd-451a-bd34-5f62b424319a@app.fastmail.com> <290910DE-9A03-4AE6-B348-073D5DA96ACC@gmail.com> <4B243750-12BE-4C16-A769-A803268F40E3@gmail.com> To: Arseniy Mukhin X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Nov 6, 2025, at 01:51, Arseniy Mukhin = wrote: >=20 > On Wed, Nov 5, 2025 at 12:22=E2=80=AFPM Chao Li = wrote: >>=20 >>=20 >>=20 >>> On Nov 2, 2025, at 04:41, Arseniy Mukhin = wrote: >>>=20 >>> This condition seems to be redundant. I would say it should always = be >>> true, otherwise it would mean that somebody allowed the listener to >>> skip our notification. >>=20 >> Hi Arseniy, >>=20 >=20 > Hi Chao, >=20 >> Did you read the example I explained in my previous email? >>=20 >=20 > Yes, I read it. Thank you for the example. It shows the case where we > can fail to apply 'direct advancement'. I think there are several > cases where it can happen. IIUC all such cases are about lagging > listeners that failed to catch up with the head before the notifier > tries to apply 'direct advancement' to them. Your example is about > listeners that finished reading but didn't update their positions > because they were stuck on the lock. I think it is also possible that > the listener can be in the process of reading or even didn't start > reading at all (for example listener backend is in the active > transaction at the moment). In these cases we also can't apply direct > advancement. Don't know if some of these examples are more important, > maybe some of them can be met more frequently. Cool, you got my idea. What I was thinking is to handle both sleeping = listeners and =E2=80=9Cslow=E2=80=9D listeners. In my view, which = shouldn=E2=80=99t be too much complicated. >=20 > I think the current version of 'direct advancement' will work good for > 'sleepy' listeners, but probably can be not very efficient for > listeners that get notifications frequently, don't know. But maybe > it's ok, we have optimization that sometimes works and have a quite > simple implementation. >=20 That=E2=80=99s what we don=E2=80=99t know. We now lack a performance = test for evaluating how =E2=80=9Cdirect advancement=E2=80=9D efficiently = helps if it only handles sleeping listeners. So what I was suggesting is = that we should first create some tests, maybe also add a few more = statistics, so that we can evaluate different solutions. If a simple = implementation that only handles sleeping listeners would have performed = good enough, of course we can take it; otherwise we may need to either = pursue a better solution. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/