Add callbacks for fixed-numbered stats flush in pgstats

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Add callbacks for fixed-numbered stats flush in pgstats
Date: 2024-09-03 04:48:59
Message-ID: ZtaVO0N-aTwiAk3w@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

The last TODO item I had in my bucket about the generalization of
pgstats is the option to a better control on the flush of the stats
depending on the kind for fixed-numbered stats. Currently, this is
controlled by pgstat_report_stat(), that includes special handling for
WAL, IO and SLRU stats, with two generic concepts:
- Check if there are pending entries, allowing a fast-path exit.
- Do the actual flush, with a recheck on pending entries.

SLRU and IO control that with one variable each, and WAL uses a
routine for the same called pgstat_have_pending_wal(). Please find
attached a patch to generalize the concept, with two new callbacks
that can be used for fixed-numbered stats. SLRU, IO and WAL are
switched to use these (the two pgstat_flush_* routines have been kept
on purpose). This brings some clarity in the code, by making
have_iostats and have_slrustats static in their respective files. The
two pgstat_flush_* wrappers do not need a boolean as return result.

Running Postgres on scissors with a read-only workload that does not
trigger stats, I was not able to see a difference in runtime, but that
was on my own laptop, and I am planning to do more measurements on a
bigger machine.

This is in the same line of thoughts as the recent thread about the
backend init callback, generalizing more the whole facility:
https://www.postgresql.org/message-id/ZtZr1K4PLdeWclXY@paquier.xyz

Like the other one, I wanted to send that a few days ago, but well,
life likes going its own ways sometimes.

Thanks,
--
Michael

Attachment Content-Type Size
0001-Add-callbacks-to-control-flush-of-fixed-numbered-sta.patch text/x-diff 10.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2024-09-03 04:59:37 Re: Virtual generated columns
Previous Message Bertrand Drouvot 2024-09-03 04:35:28 Re: define PG_REPLSLOT_DIR