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 1v2oa1-007gba-IQ for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Sep 2025 10:24:33 +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 1v2oZz-00E919-AA for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Sep 2025 10:24:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v2oZy-00E910-Ok for pgsql-hackers@lists.postgresql.org; Sun, 28 Sep 2025 10:24:31 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1v2oZw-000KHg-23 for pgsql-hackers@postgresql.org; Sun, 28 Sep 2025 10:24:30 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id E98477A005D; Sun, 28 Sep 2025 06:24:27 -0400 (EDT) Received: from phl-imap-03 ([10.202.2.93]) by phl-compute-04.internal (MEProxy); Sun, 28 Sep 2025 06:24:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1759055067; x=1759141467; bh=zmKpA+Exoo1+yncsbZu6fp80LbEkAdD0LBv5Sc9w2G8=; b= E2Ks3qgB8VsnI6Kmp8aggXDpZ3hvF47ZZb//2rQt5RZZW7kpVultcGKBsHHWFClX Tok/9ZGHO8zCy2Mp0dkynZT2QYtQQ5trJuY0oy7xfmZFUx+7r5Od6wRU4vidRmju hF81mMUii94qbrYh+czt9LTz60w/jS1yZls7O8aIkMxCRi21K+JKlDbuhG4HkmMT Dt8d2NOKYCUzw6RQ2v4h8eoJu2/g5c3nzfgN/qYZoDIzeGFgXLy+2KUhZYGhNl5e pdoskBgBvSY9ey45dSET25T9pG7U+7yMsrwXzI2N6FRM9XTJ5Y1Jf+a9hJFureQ5 NZj7Vykemmy7jDVDZwlgvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1759055067; x= 1759141467; bh=zmKpA+Exoo1+yncsbZu6fp80LbEkAdD0LBv5Sc9w2G8=; b=K z4HV7ESpJMirmd/D0GccLY2gP6sdWXGOqNleFS8KvT1vbRPpZmtHQxlPjA537/nn YcTo8oUahoGd7o4gW1dki2aWs6FlM75T9UB5Ju0BWpH52QC3yzhD7tbkXQ0zxK2K D2zI9jkEaWKjylsiLNE/X9ZW3Sils6aJTEXEWE+xGkM5gfF80oyGsX9e9ZQV4aQX o7e7w0xm2FJxCnDOr3P5ixmlUtSxfTnY2qY7PlRvPCgxICFJAMH9uCtvCkd04z80 DieYH7Qlex9fByBsQdAkHqost5WU//t70k/b3fBBh/DLkr+CzRVOvuLu31BqRzka 93Q2GKCcXM+tlpQWVJr8A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdejgeekkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdflohgvlhcu lfgrtghosghsohhnfdcuoehjohgvlhestghomhhpihhlvghrrdhorhhgqeenucggtffrrg htthgvrhhnpefggfeuheefheeufeegkeeifeffhffgvefftdduuefhfeelteegleehhfdt ieevgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hjohgvlhestghomhhpihhlvghrrdhorhhgpdhnsggprhgtphhtthhopeeipdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehlihdrvghvrghnrdgthhgrohesghhmrghilhdrtg homhdprhgtphhtthhopehrihhshhhurdhpohhsthhgrhgvshesghhmrghilhdrtghomhdp rhgtphhtthhopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtth hopehhlhhinhhnrghkrgesihhkihdrfhhipdhrtghpthhtohepphhgshhqlhdqhhgrtghk vghrshesphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepthhglhesshhsshdrph hghhdrphgrrdhush X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 0B3DD18E0074; Sun, 28 Sep 2025 06:24:27 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: AZ7XRsRLdGms Date: Sun, 28 Sep 2025 12:24:06 +0200 From: "Joel Jacobson" To: "Chao Li" Cc: "Tom Lane" , "Thomas Munro" , pgsql-hackers , "Heikki Linnakangas" , "Rishu Bagga" Message-Id: In-Reply-To: <9186C6D0-F7A9-482A-9183-89E530B57E36@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> Subject: Re: Optimize LISTEN/NOTIFY Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Sep 26, 2025, at 11:44, Chao Li wrote: >> On Sep 26, 2025, at 17:32, Joel Jacobson wrote: >>=20 >> On Fri, Sep 26, 2025, at 04:26, Chao Li wrote: >>=20 >>> I think what you explained is partially correct. >>>=20 >>> Based on my understanding, any backend process may call=20 >>> SignalBackends(), which means that it=E2=80=99s possible that multip= le backend=20 >>> processes may call SignalBackends() concurrently. >>>=20 >>> Looking at your code, between checking=20 >>> QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) and set the flag to true, there= is=20 >>> a block of code (the =E2=80=9Cif-else=E2=80=9D) to run, so that it=E2= =80=99s possible that=20 >>> multiple backend processes have passed the=20 >>> QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) check, then multiple signals wi= ll=20 >>> be sent to a process, which will lead to duplicate timeout enabled i= n=20 >>> the receiver process. >>=20 >> I don't see how that can happen; we're checking wakeup_pending_flag >> while holding an exclusive lock, so I don't see how multiple backend >> processes could be within the region where we check/set >> wakeup_pending_flag, at the same time? >>=20 >> /Joel > > I might miss the factor of holding an exclusive lock. I will revisit=20 > that part again. I've re-read this entire thread, and I actually think my original approaches are more promising, that is, the 0001-optimize_listen_notify-v4.patch patch, doing multicast targeted signaling. Therefore, merely consider the latest patch as PoC with some possible interesting ideas. Before this patch, I had never used PostgreSQL's timeout mechanism before, so I didn't consider it when thinking about how to solve the remaining problems with 0001-optimize_listen_notify-v4.patch, which currently can't guarantee that all listening backends will eventually catch up, since it just kicks one of the most lagging ones, for each notification. This could be a problem in practise if there is a long period of time with no notifications coming in. Then some listening backends could end up not being signaled and would stay behind, preventing the queue tail from advancing. I'm thinking maybe somehow we can use the timeout mechanism here, but I'm not sure how yet. Any ideas? /Joel