From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use the pairing heap instead of a flat array for LSN replay wait
Date: Wed, 03 Apr 2024 15:15:55 +0000
Message-ID: <E1rs2LC-000Jnr-GT@gemulon.postgresql.org> (raw)
Use the pairing heap instead of a flat array for LSN replay waiters
06c418e163 introduced pg_wal_replay_wait() procedure allowing to wait for
the particular LSN to be replayed on standby. The waiters were stored in
the flat array. Even though scanning small arrays is fast, that might be a
problem at scale (a lot of waiting processes).
This commit replaces the flat shared memory array with the pairing heap,
which holds the waiter with the least LSN at the top. This gives us O(log N)
complexity for both inserting and removing waiters.
Reported-by: Alvaro Herrera
Discussion: https://postgr.es/m/202404030658.hhj3vfxeyhft%40alvherre.pgsql
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/bf1e65080629e2b0ac47ffe245576da96eff8420
Modified Files
--------------
src/backend/access/transam/xlogrecovery.c | 2 +-
src/backend/commands/waitlsn.c | 168 ++++++++++++++----------------
src/backend/lib/pairingheap.c | 18 +++-
src/include/commands/waitlsn.h | 44 +++++++-
src/include/lib/pairingheap.h | 3 +
5 files changed, 140 insertions(+), 95 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Use the pairing heap instead of a flat array for LSN replay wait
In-Reply-To: <E1rs2LC-000Jnr-GT@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox