Re: Pluggable cumulative statistics
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-07-03T09:47:15Z
Lists: pgsql-hackers
Attachments
- v3-0001-Rework-handling-of-fixed-numbered-statistics-in-p.patch (text/x-diff) patch v3-0001
- v3-0002-Switch-PgStat_Kind-from-enum-to-uint32.patch (text/x-diff) patch v3-0002
- v3-0003-Introduce-pluggable-APIs-for-Cumulative-Statistic.patch (text/x-diff) patch v3-0003
- v3-0004-doc-Add-section-for-Custom-Cumulative-Statistics-.patch (text/x-diff) patch v3-0004
- v3-0005-injection_points-Add-statistics-for-custom-points.patch (text/x-diff) patch v3-0005
- v3-0006-Add-support-for-fixed-numbered-statistics-in-plug.patch (text/x-diff) patch v3-0006
On Fri, Jun 21, 2024 at 08:13:15AM +0900, Michael Paquier wrote: > On Thu, Jun 20, 2024 at 02:27:14PM +0000, Bertrand Drouvot wrote: >> On Thu, Jun 20, 2024 at 09:46:30AM +0900, Michael Paquier wrote: >> I think it makes sense to follow the same "behavior" as the custom >> wal resource managers. That, indeed, looks much more simpler than v1. > > Thanks for the feedback. While looking at a different patch from Tristan in this area at [1], I still got annoyed that this patch set was not able to support the case of custom fixed-numbered stats, so as it is possible to plug in pgstats things similar to the archiver, the checkpointer, WAL, etc. These are plugged in shared memory, and are handled with copies in the stats snapshots. After a good night of sleep, I have come up with a good solution for that, among the following lines: - PgStat_ShmemControl holds an array of void* indexed by PGSTAT_NUM_KINDS, pointing to shared memory areas allocated for each fixed-numbered stats. Each entry is allocated a size corresponding to PgStat_KindInfo->shared_size. - PgStat_Snapshot holds an array of void* also indexed by PGSTAT_NUM_KINDS, pointing to the fixed stats stored in the snapshots. These have a size of PgStat_KindInfo->shared_data_len, set up when stats are initialized at process startup, so this reflects everywhere. - Fixed numbered stats now set shared_size, and we use this number to determine the size to allocate for each fixed-numbered stats in shmem. - A callback is added to initialize the shared memory assigned to each fixed-numbered stats, consisting of LWLock initializations for the current types of stats. So this initialization step is moved out of pgstat.c into each stats kind file. All that has been done in the rebased patch set as of 0001, which is kind of a nice cleanup overall because it removes all the dependencies to the fixed-numbered stats structures from the "main" pgstats code in pgstat.c and pgstat_shmem.c. The remaining patches consist of: - 0002, Switch PgStat_Kind to a uint32. Cleanup. - 0003 introduces the pluggable stats facility. Feeding on the refactoring for the fixed-numbered stats in 0001, it is actually possible to get support for these in the pluggable APIs by just removing the restriction in the registration path. This extends the void* arrays to store references that cover the range of custom kind IDs. - 0004 has some docs. - 0005 includes an example of implementation for variable-numbered stats with the injection_points module. - 0006 is new for this thread, implementing an example for fixed-numbered stats, using again the injection_points module. This stuff gathers stats about the number of times points are run, attached and detached. Perhaps that's useful in itself, I don't know, but it provides the coverage I want for this facility. While on it, I have applied one of the cleanup patches as 9fd02525793f. [1]: https://www.postgresql.org/message-id/ZoNytpoHOzHGBLYi@paquier.xyz -- Michael
Commits
-
injection_points: Add some fixed-numbered statistics
- f68cd847fa40 18.0 landed
-
injection_points: Add some cumulative stats for injection points
- 75534436a477 18.0 landed
-
Add helper routines to retrieve data for custom fixed-numbered pgstats
- 2eff9e678d35 18.0 landed
-
Introduce pluggable APIs for Cumulative Statistics
- 7949d9594582 18.0 landed
-
Switch PgStat_Kind from an enum to a uint32 type
- 3188a4582a8c 18.0 landed
-
Improve comment of pgstat_read_statsfile()
- 72c0b24b2ddd 18.0 landed
-
Add a new 'F' entry type for fixed-numbered stats in pgstats file
- 9e4664d950c1 18.0 landed
-
Add PgStat_KindInfo.init_shmem_cb
- 21471f18e9d9 18.0 landed
-
Use pgstat_kind_infos to write fixed shared statistics
- b68b29bc8fec 18.0 landed
-
Replace hardcoded identifiers of pgstats file by #defines
- 9fd02525793f 18.0 landed