On Mon, Nov 3, 2025, at 12:02, Heikki Linnakangas wrote:
> I wrote another little stand-alone performance test program for this, 
> attached. It launches N connections that send NOTIFYs to a single 
> channel as fast as possible, and M threads that listen for the 
> notifications. I ran it with different combinations of N and M, on 
> 'master' and on REL_14_STABLE (which didn't have SLRU banks) and I 
> cannot discern any performance difference from these patches. So it 
> seems that holding the SLRU (bank) lock across the 
> TransactionIdDidCommit() calls is fine.

Nice! That for the benchmark code! I took the liberty of hacking a bit
on it, and added support for multiple channels, with separate listener
and notifier threads per channel. Each notification now carries the
notifier ID, a sequence number, and a send timestamp. Listeners verify
that sequence numbers arrive in order and record delivery latency. The
program collects latency measurements into fixed buckets and reports
them once per second together with total and per-second send/receive
counts.

Also added a short delay before starting notifiers so that listeners
have time to issue their LISTEN commands, and a new --channels option,
and the meaning of --listeners and --notifiers was changed to apply per
channel.

Also fixed so the code could be compiled outside of the PostgreSQL
source code repo, if wanting to build this as stand-alone tool.

I've benchmarked master vs 0001+0002 and can't notice any differences;
see attached output from benchmark runs.

/Joel
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 1 
--notifiers 1 --channels 1
10 s: 901000 sent (91172/s), 901000 received (91172/s)
 0.00-0.01ms     #          25 (0.0%) avg: 0.009ms
 0.01-0.10ms     #########  900872 (100.0%) avg: 0.015ms
 0.10-1.00ms     #          101 (0.0%) avg: 0.157ms
 1.00-10.00ms    #          2 (0.0%) avg: 1.383ms
 10.00-100.00ms             0 (0.0%) avg: 0.000ms
>100.00ms                  0 (0.0%) avg: 0.000ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 2 
--notifiers 2 --channels 2
10 s: 758321 sent (75439/s), 1516644 received (150878/s)
 0.00-0.01ms     #          7 (0.0%) avg: 0.009ms
 0.01-0.10ms     #########  1504034 (99.2%) avg: 0.043ms
 0.10-1.00ms     #          12026 (0.8%) avg: 0.115ms
 1.00-10.00ms    #          577 (0.0%) avg: 1.335ms
 10.00-100.00ms             0 (0.0%) avg: 0.000ms
>100.00ms                  0 (0.0%) avg: 0.000ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 4 
--notifiers 4 --channels 4
10 s: 333820 sent (32926/s), 1335295 received (131715/s)
 0.00-0.01ms                0 (0.0%) avg: 0.000ms
 0.01-0.10ms     #          364 (0.0%) avg: 0.079ms
 0.10-1.00ms     #########  1326782 (99.4%) avg: 0.376ms
 1.00-10.00ms    #          8149 (0.6%) avg: 1.430ms
 10.00-100.00ms             0 (0.0%) avg: 0.000ms
>100.00ms                  0 (0.0%) avg: 0.000ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 8 
--notifiers 8 --channels 8
10 s: 88418 sent (9253/s), 707368 received (73993/s)
 0.00-0.01ms                0 (0.0%) avg: 0.000ms
 0.01-0.10ms                0 (0.0%) avg: 0.000ms
 0.10-1.00ms                0 (0.0%) avg: 0.000ms
 1.00-10.00ms    #########  658378 (93.1%) avg: 6.469ms
 10.00-100.00ms  #          48927 (6.9%) avg: 19.445mss
>100.00ms       #          63 (0.0%) avg: 106.025ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 16 
--notifiers 16 --channels 16
10 s: 22858 sent (2320/s), 365987 received (37302/s)
 0.00-0.01ms                0 (0.0%) avg: 0.000ms
 0.01-0.10ms                0 (0.0%) avg: 0.000ms
 0.10-1.00ms                0 (0.0%) avg: 0.000ms
 1.00-10.00ms               0 (0.0%) avg: 0.000ms
 10.00-100.00ms  #          69705 (19.0%) avg: 93.428ms
>100.00ms       ########   296282 (81.0%) avg: 111.203ms
^C
joel@Mac pg_async_notify_test %
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 1 
--notifiers 1 --channels 1
10 s: 880520 sent (89409/s), 880519 received (89408/s)
 0.00-0.01ms     #          17 (0.0%) avg: 0.008ms
 0.01-0.10ms     #########  880350 (100.0%) avg: 0.015ms
 0.10-1.00ms     #          150 (0.0%) avg: 0.169ms
 1.00-10.00ms    #          2 (0.0%) avg: 1.427ms
 10.00-100.00ms             0 (0.0%) avg: 0.000ms
>100.00ms                  0 (0.0%) avg: 0.000ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 2 
--notifiers 2 --channels 2
10 s: 744302 sent (74199/s), 1488608 received (148402/s)
 0.00-0.01ms     #          12 (0.0%) avg: 0.009ms
 0.01-0.10ms     #########  1470763 (98.8%) avg: 0.045ms
 0.10-1.00ms     #          17293 (1.2%) avg: 0.116ms
 1.00-10.00ms    #          540 (0.0%) avg: 1.447ms
 10.00-100.00ms             0 (0.0%) avg: 0.000ms
>100.00ms                  0 (0.0%) avg: 0.000ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 4 
--notifiers 4 --channels 4
10 s: 302339 sent (32417/s), 1209366 received (129677/s)
 0.00-0.01ms                0 (0.0%) avg: 0.000ms
 0.01-0.10ms     #          58 (0.0%) avg: 0.072ms
 0.10-1.00ms     #########  1202143 (99.4%) avg: 0.432ms
 1.00-10.00ms    #          7165 (0.6%) avg: 1.492ms
 10.00-100.00ms             0 (0.0%) avg: 0.000ms
>100.00ms                  0 (0.0%) avg: 0.000ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 8 
--notifiers 8 --channels 8
10 s: 94129 sent (9464/s), 753090 received (75715/s)
 0.00-0.01ms                0 (0.0%) avg: 0.000ms
 0.01-0.10ms                0 (0.0%) avg: 0.000ms
 0.10-1.00ms                0 (0.0%) avg: 0.000ms
 1.00-10.00ms    #########  714160 (94.8%) avg: 6.382ms
 10.00-100.00ms  #          38757 (5.1%) avg: 19.804ms
>100.00ms       #          173 (0.0%) avg: 105.323ms
^C
joel@Mac pg_async_notify_test % ./pg_async_notify_test --listeners 16 
--notifiers 16 --channels 16
10 s: 24874 sent (2547/s), 398031 received (40618/s)
 0.00-0.01ms                0 (0.0%) avg: 0.000ms
 0.01-0.10ms                0 (0.0%) avg: 0.000ms
 0.10-1.00ms                0 (0.0%) avg: 0.000ms
 1.00-10.00ms    #          30 (0.0%) avg: 6.204ms
 10.00-100.00ms  ####       197439 (49.6%) avg: 93.703ms
>100.00ms       #####      200564 (50.4%) avg: 106.259ms
^C
joel@Mac pg_async_notify_test %

Attachment: async-notify-test-2.c
Description: Binary data

Reply via email to