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 1vBqVR-005thl-Fp for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 08:17:08 +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 1vBqVQ-0074BU-Do for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Oct 2025 08:17:07 +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 1vBqVQ-0074BM-4f for pgsql-hackers@lists.postgresql.org; Thu, 23 Oct 2025 08:17:07 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vBqVM-003JFq-1C for pgsql-hackers@postgresql.org; Thu, 23 Oct 2025 08:17:06 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-780fc3b181aso365686b3a.2 for ; Thu, 23 Oct 2025 01:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761207423; x=1761812223; 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=EcjXQ24NHgOsYIQlpopVTTqjz/r1OpBmzVgIU6waTeE=; b=dUXdBCwaneM1eL2DhyysJh9mBn1msuaUQdqnP7vQC5F+/LLIepdogA8X5xbC/LiefX ORs6HJ1BB4EZOCiozOmZdS5k+x2AuoKe1j10L5kDJzZTPgjCsX48b2AjiisLVwANUMwd n1kOziUr3gKCcJ/kYHUxMl2EE0z6wesmRI5aGDRWSzQTzxSHCDDEzIFlW2noH+wIL9mA rXwkZkPGKxOcgJ9dw160sv3OFssW9hv9EbQVcr6vFYupiws+vHdfRdAnvZ4nV1iiMvVY 5J/NOC4SRijSg6VIg52fxsP/IzMU6Zcthzqau1tqDzh398LotFFpor3prHdXJ1cl+R84 0suQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761207423; x=1761812223; 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=EcjXQ24NHgOsYIQlpopVTTqjz/r1OpBmzVgIU6waTeE=; b=GxVjFt4OTxan5UwEtNbsnvIQoGqTKGIwhKVBNqG/+3tTU+tyyiKTG31nzCcTCz7Mzs DqLu6vRtVk73CA8X9pomRrDZiDDeYZym+yZD0dcbI/HIOr8CU2ihCp9Zh+/Ni0R4O1c9 /57+gbrmHzeD31csy2/Xiv8IJVploS01af/mUY5gsGc//Uy1Pi8+GN1wvJ78QOarGBTN uF7xt/+1k0bz1LTz1+lUg9GwwGh8XDhgkOV29iPxvSubu0YpxmxUtc5dr1H6yy5hr2l+ V5rCaQu/be3vSPn3dYoj+naxm/Zzrn1WVGp+i7kGDkwX9Uo7IEQSwIKJMqLBGHT/W5CP sAFw== X-Forwarded-Encrypted: i=1; AJvYcCVGZGNErT9SsOJSr1Or35iUI2JNG5t5yhbx7G2FevRWbe87oJtBnaPYO2fZWlv3qPI3dD/nY2PAaKhXcrc7@postgresql.org X-Gm-Message-State: AOJu0YyiGxci6CA3NvzoZiR3GDYx2KOMbu8Ujr+PouN1aNFEl7zHwJg9 K2v6XCfWlaR3RDwMDs9X/0fBXaeVChDSEOZcbAcQe1OCthVEJjbhWYFc X-Gm-Gg: ASbGncslFd2T/Om67c36Su5SNXOZQHuPWvYesWQ2SW7l6qubWpsWW10SNjl2AhBUsOq 0HbjRu7URPy2opkN/gVpDPZepNZhH1eLC1zUf88Al3IhQ/+j5kMKil9KmSLDtgWNk4mUJsKJ+mS RdiUBkRK/XXwiVdShGMBQkdYqicAgajQKuOEs1KMXVeEXnGjir2GnGEmfsbFlRFQC7mYL5CrCHV /fCaVENYb1aAYRmKHCAl9Xbx8wRSjtHu/3BidMWDQuYCdctKvjVSXw/OmXY14rs6VPoe+fsmngK gwsZoOuzHTRW5twrlzcT2y2bzK0qAijPEIfFXArKgbVyQNn1a99j6pOPuCUtij5oFE0/ob1sPBo pirsv3UAzsFikkKVQku0t+WNQNkJpEEyxrroE957+NW0b5WvFsbTVsMMkkVWgtTGdSaBl8h2sDz PahYgxxWsnqnC3ctd+POuaTA== X-Google-Smtp-Source: AGHT+IFXo3bKCj3Y52OCOTyOXD9J/1tDjuuN6b7OxfFjZH5roTuan+1oPL0h4wd9dLAQVq5ltxS/aA== X-Received: by 2002:a05:6a20:7287:b0:249:d3d:a50b with SMTP id adf61e73a8af0-33c626aeccbmr2350313637.59.1761207423432; Thu, 23 Oct 2025 01:17:03 -0700 (PDT) Received: from smtpclient.apple ([170.178.170.211]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-33e223d1265sm4955533a91.3.2025.10.23.01.17.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Oct 2025 01:17:02 -0700 (PDT) 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, 23 Oct 2025 16:16:27 +0800 Cc: Joel Jacobson , Tom Lane , pgsql-hackers Content-Transfer-Encoding: quoted-printable Message-Id: <14865EB6-0BF4-462B-9072-10BDAC10C052@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> 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 Oct 21, 2025, at 00:43, Arseniy Mukhin = wrote: >=20 >=20 > I managed to reproduce the race with v20-alt3. I tried to write a TAP > test reproducing the issue, so it was easier to validate changes. > Please find the attached TAP test. I added it to some random package > for simplicity. >=20 With alt3, as we have acquired the notification lock after reading every = message to update the POS, I think we can do a little bit more = optimization: The notifier: in SignalBackend() * Now we check if a listener=E2=80=99s pos equals to beforeWritePos, = then we do =E2=80=9Cdirectly advancement=E2=80=9D * We can change to if a listener=E2=80=99s pos is between = beforeWritePos and afterWritePos, then we can do the advancement. The listener: in asyncQueueReadAllNotifications(): * With alt3, we only lock and update pos * We can do more. If current pos in shared memory is after that = local pos, then meaning some notifier has done an advancement, so it can = stop reading. I tried to run your TAP test on my MacBook, but failed: ``` t/008_listen-pos-race.pl .. Dubious, test returned 32 (wstat 8192, = 0x2000) No subtests run Test Summary Report ------------------- t/008_listen-pos-race.pl (Wstat: 8192 (exited 32) Tests: 0 Failed: 0) Non-zero exit status: 32 Parse errors: No plan found in TAP output Files=3D1, Tests=3D0, 3 wallclock secs ( 0.01 usr 0.01 sys + 0.10 = cusr 0.29 csys =3D 0.41 CPU) Result: FAIL ``` I didn=E2=80=99t spend time debugging the problem. If you can figure the = problem, maybe I can run the test from my side. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/