diff options
| author | Andres Freund | 2023-03-30 21:23:14 +0000 |
|---|---|---|
| committer | Andres Freund | 2023-03-30 21:23:14 +0000 |
| commit | ca7b3c4c00042038ba9c282c4807e05c0a527e42 (patch) | |
| tree | 73ede8f1a9988dc4f699d2b2c95c75a7982af531 /src/include | |
| parent | 122376f028a0e31b91d6c6bad2a9a6e994708547 (diff) | |
pg_stat_wal: Accumulate time as instr_time instead of microseconds
In instr_time.h it is stated that:
* When summing multiple measurements, it's recommended to leave the
* running sum in instr_time form (ie, use INSTR_TIME_ADD or
* INSTR_TIME_ACCUM_DIFF) and convert to a result format only at the end.
The reason for that is that converting to microseconds is not cheap, and can
loose precision. Therefore this commit changes 'PendingWalStats' to use
'instr_time' instead of 'PgStat_Counter' while accumulating 'wal_write_time'
and 'wal_sync_time'.
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>
Discussion: https://postgr.es/m/1feedb83-7aa9-cb4b-5086-598349d3f555@gmail.com
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/pgstat.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/include/pgstat.h b/src/include/pgstat.h index c2bae8358a2..17ee94d8b66 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -435,6 +435,21 @@ typedef struct PgStat_WalStats TimestampTz stat_reset_timestamp; } PgStat_WalStats; +/* + * This struct stores wal-related durations as instr_time, which makes it + * cheaper and easier to accumulate them, by not requiring type + * conversions. During stats flush instr_time will be converted into + * microseconds. + */ +typedef struct PgStat_PendingWalStats +{ + PgStat_Counter wal_buffers_full; + PgStat_Counter wal_write; + PgStat_Counter wal_sync; + instr_time wal_write_time; + instr_time wal_sync_time; +} PgStat_PendingWalStats; + /* * Functions in pgstat.c @@ -748,7 +763,7 @@ extern PGDLLIMPORT SessionEndType pgStatSessionEndCause; */ /* updated directly by backends and background processes */ -extern PGDLLIMPORT PgStat_WalStats PendingWalStats; +extern PGDLLIMPORT PgStat_PendingWalStats PendingWalStats; #endif /* PGSTAT_H */ |
