pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix performance regression with flush of pending fixed-numbered
Date: Sun, 27 Jul 2025 23:16:26 +0000
Message-ID: <E1ugAbR-001377-32@gemulon.postgresql.org> (raw)

Fix performance regression with flush of pending fixed-numbered stats

The callback added in fc415edf8ca8 used to check if there is any pending
data to flush for fixed-numbered statistics, done by looping across all
the builtin and custom stats kinds with a call to have_fixed_pending_cb,
is proving to able to show in workloads that do not report any stats
(read-only, no function calls, no WAL, no IO, etc).  The code used in
v17 was cheaper than that what HEAD has introduced, relying on three
boolean checks for WAL, SLRU and IO stats.

This commit switches the code to use a more efficient approach than
fc415edf8ca8, with a single boolean flag that can be switched to "true"
by any fixed-numbered stats kinds to force pgstat_report_stat() to go
through one round of reports.  The flag is reset by pgstat_report_stat()
once a full round of reports is done.  The flag being false means that
fixed-numbered stats kinds saw no activity, and that there is no pending
data to flush.

ac000fca743e took one step in improving the performance by reducing the
number of stats kinds that the backend can hold.  This commit takes a
more drastic step by bringing back the code efficiency to what it was
before v18 with a cheap check at the beginning of pgstat_report_stat()
for its fast-exit path.

The callback have_static_pending_cb is removed as an effect of all that.

Reported-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/eb224uegsga2hgq7dfq3ps5cduhpqej7ir2hjxzzozjthrekx5@dysei6buqthe
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/793928c2d5ac8e60e1e4054fa3b986369777896d

Modified Files
--------------
src/backend/access/transam/xlog.c           | 10 ++++++
src/backend/utils/activity/pgstat.c         | 52 +++++++++++------------------
src/backend/utils/activity/pgstat_backend.c | 14 ++------
src/backend/utils/activity/pgstat_io.c      | 10 +-----
src/backend/utils/activity/pgstat_slru.c    | 10 +-----
src/backend/utils/activity/pgstat_wal.c     | 20 +++++------
src/include/utils/pgstat_internal.h         | 34 ++++++++++---------
7 files changed, 62 insertions(+), 88 deletions(-)



view thread (2+ messages)

Message-ID: <E1ugAbR-001377-32@gemulon.postgresql.org>
Permalink:  ../E1ugAbR-001377-32@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ugAbR-001377-32@gemulon.postgresql.org

 · 

reply

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: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix performance regression with flush of pending fixed-numbered
  In-Reply-To: <E1ugAbR-001377-32@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