-
Notifications
You must be signed in to change notification settings - Fork 2
Permalink
Choose a base ref
{{ refName }}
default
Choose a head ref
{{ refName }}
default
Comparing changes
Choose two branches to see what’s changed or to start a new pull request.
If you need to, you can also or
learn more about diff comparisons.
Open a pull request
Create a new pull request by comparing changes across two branches. If you need to, you can also .
Learn more about diff comparisons here.
base repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf/5912~1
Could not load branches
Nothing to show
Loading
Could not load tags
Nothing to show
{{ refName }}
default
Loading
...
head repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cf/5912
Could not load branches
Nothing to show
Loading
Could not load tags
Nothing to show
{{ refName }}
default
Loading
- 3 commits
- 3 files changed
- 2 contributors
Commits on Aug 4, 2025
-
Optimize LISTEN/NOTIFY signaling with a lock-free atomic state machine
This commit introduces a powerful pattern for modernizing inter-process communication by refactoring the LISTEN/NOTIFY subsystem to use a lock-free, atomic finite state machine (FSM). This directly addresses the historical lack of safe, efficient state synchronization primitives. Previously, if multiple transactions sent notifications concurrently, each would unconditionally attempt to signal all listening backends. This resulted in a storm of superfluous signals to listeners that were already pending a wakeup, causing unnecessary system call overhead. By introducing an atomic per-backend state (IDLE, SIGNALLED, PROCESSING) in shared memory and manipulated via compare-and-swap (CAS), this inefficiency is eliminated. A notifier can now atomically transition a listener's state from IDLE to SIGNALLED, ensuring that only the first notifier for a given idle listener dispatches a wakeup. The FSM also robustly handles race conditions where new notifications arrive while a listener is PROCESSING, guaranteeing no work is ever missed. This FSM pattern is a generalizable solution for managing concurrency in PostgreSQL. By modeling inter-process interactions as explicit state transitions, we can build more robust and performant subsystems. This commit demonstrates the pattern's effectiveness within async.c, and by cleanly solving the state management problem first, it enables a subsequent, trivial optimization of the wakeup mechanism itself.
Configuration menu - View commit details
-
Copy full SHA for a54954c - Browse repository at this point
Copy the full SHA a54954cView commit details -
Optimize LISTEN/NOTIFY wakeup by replacing signal with direct SetLatch
Building upon the robust atomic state machine introduced in the previous commit, this change completes the modernization of NOTIFY IPC by replacing its wakeup mechanism. With inter-process state now managed reliably, the heavyweight SIGUSR1 signal is no longer necessary and is replaced with a much more efficient, direct "poke." The async.c notifier now replaces its call to SendProcSignal with a direct call to SetLatch on the target backend's procLatch. This is a significant optimization because WaitLatch, which listeners already use for blocking, is underpinned by the modern WaitEventSet abstraction (kqueue, epoll, etc.). We now leverage this existing, highly efficient infrastructure for the wakeup, completely bypassing the kill() syscall and the SIGUSR1 signal handler for all NOTIFY events. This demonstrates a powerful, two-step migration pattern: 1. First, solve a subsystem's state synchronization problem with a lock-free, atomic FSM to eliminate redundant signaling. 2. Then, with state management handled, make the wakeup itself cheaper by replacing the expensive signal with a direct SetLatch. This staged approach allows us to modernize subsystems incrementally and safely. By applying this pattern to async.c, we prove its viability and simplicity, creating a clear template for other parts of the system to follow in moving towards a more performant, signal-free IPC model.
Configuration menu - View commit details
-
Copy full SHA for b8f1647 - Browse repository at this point
Copy the full SHA b8f1647View commit details -
[CF 5912] Optimize LISTEN/NOTIFY
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5912 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/[email protected] Author(s): Joel Jacobson
Commitfest Bot committedAug 4, 2025 Configuration menu - View commit details
-
Copy full SHA for 9783317 - Browse repository at this point
Copy the full SHA 9783317View commit details
Loading
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff cf/5912~1...cf/5912