Thread

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

    Joel Jacobson <joel@compiler.org> — 2025-10-30T23:08:04Z

    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