Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: "Heikki Linnakangas" <hlinnaka(at)iki(dot)fi>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue
Date: 2025-10-30 23:08:04
Message-ID: e1e4909b-66b9-43d8-8942-529b7519c758@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 30, 2025, at 14:25, Heikki Linnakangas wrote:
> Joel, since you've been working on some optimizations in this area too,
> would you happen to have some suitable performance test scripts for this?

Glad you asked. I'm actually working on a benchmark+correctness tester.
It's very much work-in-progress though, don't look too much at the code,
or your eyes will bleed.

It's a combined benchmark + correctness tester, that verifies that only
the expected notifications are received on the expected connections,
while at the same time doing timing measurements.

```
% ./pg_bench_lino --help
Usage: ./pg_bench_lino [OPTIONS]

PostgreSQL LISTEN/NOTIFY Benchmark Tool (CLI version)

Options:
-c, --connections N Number of database connections (default: 1)
-n, --channels N Number of notification channels (default: 1)
-t, --tick-ms N Tick interval in milliseconds (default: 1)
-l, --listen-prob N LISTEN probability % (default: 0.1, 0 to disable)
-u, --unlisten-prob N UNLISTEN probability % (default: 0.05, 0 to disable)
-p, --notify-prob N NOTIFY probability % (default: 1.0, 0 to disable)
-a, --unlisten-all-prob N UNLISTEN * probability % (default: 0.01, 0 to disable)
-T, --ticks N Number of ticks to run (REQUIRED)
-s, --seed N Random seed for reproducibility (default: current time)
-h, --help Show this help message
```

Example run on my MacBook M3 Max

--- master:

% ./pg_bench_lino -t 0 -c 100 -n 1000 -l 10 -u 0 -p 100 -s 42 -T 10000
Initializing 100 connections and 1000 channels...
Initialization complete. Starting benchmark...

========================================================
PostgreSQL LISTEN/NOTIFY Benchmark Results
========================================================

Configuration:
Connections: 100
Channels: 1000
Tick interval: 0 ms
LISTEN probability: 10.0000%
UNLISTEN probability: 0.0000%
NOTIFY probability: 100.0000%
UNLISTEN * probability: 0.0100%
Ticks executed: 10000
Random seed: 42

Final State:
Active connections: 100
Active channels: 1000
Listening pairs: 989
Correctness errors: 0

========================================================
Operation Statistics:
Operation Count Min(ms) Avg(ms) Max(ms)
--------------------------------------------------------
LISTEN 1009 0.016 0.029 0.291
UNLISTEN 0 - - -
UNLISTEN * 1 0.071 0.071 0.071
NOTIFY 9989 0.064 0.247 2.163
NOTIFY delivery 9989 0.072 0.277 2.170

========================================================
NOTIFY Delivery Time Distribution:

0.05-0.1ms # 4 (0.0%)
0.1-0.15ms ## 263 (2.6%)
0.15-0.2ms ####### 881 (8.8%)
0.2-0.3ms ################################################## 5907 (59.1%)
0.3-0.4ms #################### 2388 (23.9%)
0.4-0.5ms #### 525 (5.3%)
0.5-0.75ms # 18 (0.2%)
1-2ms # 2 (0.0%)
2-5ms # 1 (0.0%)

-- Optimization v22 patch:

% ./pg_bench_lino -t 0 -c 100 -n 1000 -l 10 -u 0 -p 100 -s 42 -T 10000
Initializing 100 connections and 1000 channels...
Initialization complete. Starting benchmark...

========================================================
PostgreSQL LISTEN/NOTIFY Benchmark Results
========================================================

Configuration:
Connections: 100
Channels: 1000
Tick interval: 0 ms
LISTEN probability: 10.0000%
UNLISTEN probability: 0.0000%
NOTIFY probability: 100.0000%
UNLISTEN * probability: 0.0100%
Ticks executed: 10000
Random seed: 42

Final State:
Active connections: 100
Active channels: 1000
Listening pairs: 989
Correctness errors: 0

========================================================
Operation Statistics:
Operation Count Min(ms) Avg(ms) Max(ms)
--------------------------------------------------------
LISTEN 1009 0.015 0.023 0.340
UNLISTEN 0 - - -
UNLISTEN * 1 0.056 0.056 0.056
NOTIFY 9989 0.018 0.031 2.037
NOTIFY delivery 9989 0.022 0.062 2.056

========================================================
NOTIFY Delivery Time Distribution:

0-0.05ms ################################################## 5002 (50.1%)
0.05-0.1ms ######################################### 4130 (41.3%)
0.1-0.15ms # 77 (0.8%)
0.15-0.2ms #### 427 (4.3%)
0.2-0.3ms ### 338 (3.4%)
0.3-0.4ms # 11 (0.1%)
0.4-0.5ms # 1 (0.0%)
2-5ms # 3 (0.0%)

To compile:
gcc -Wall -Wextra -g -I"$(pg_config --includedir)" -c pg_bench_lino.c -o pg_bench_lino.o
gcc pg_bench_lino.o -L"$(pg_config --libdir)" -lpq -o pg_bench_lino

/Joel

Attachment Content-Type Size
pg_bench_lino.c application/octet-stream 33.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2025-10-30 23:08:17 Re: Resetting recovery target parameters in pg_createsubscriber
Previous Message David Rowley 2025-10-30 22:41:03 Re: Potential bug introduced in PG17 with query parallelization - plan flip