diff options
| author | Tom Lane | 2007-04-30 03:23:49 +0000 |
|---|---|---|
| committer | Tom Lane | 2007-04-30 03:23:49 +0000 |
| commit | 957d08c81f9cc277725c83b9381c5154b6318a5e (patch) | |
| tree | 1c665d6e63c2cb02156df44a3519d2a0bebcaea3 /src/backend/postmaster | |
| parent | 57b82bf324285464783796e5614d5f9aadd0817f (diff) | |
Implement rate-limiting logic on how often backends will attempt to send
messages to the stats collector. This avoids the problem that enabling
stats_row_level for autovacuum has a significant overhead for short
read-only transactions, as noted by Arjen van der Meijden. We can avoid
an extra gettimeofday call by piggybacking on the one done for WAL-logging
xact commit or abort (although that doesn't help read-only transactions,
since they don't WAL-log anything).
In my proposal for this, I noted that we could change the WAL log entries
for commit/abort to record full TimestampTz precision, instead of only
time_t as at present. That's not done in this patch, but will be committed
separately.
Diffstat (limited to 'src/backend/postmaster')
| -rw-r--r-- | src/backend/postmaster/pgstat.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index be9b236d545..ad5b490a27d 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -13,7 +13,7 @@ * * Copyright (c) 2001-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.153 2007/04/21 04:10:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.154 2007/04/30 03:23:49 tgl Exp $ * ---------- */ #include "postgres.h" @@ -608,15 +608,34 @@ void allow_immediate_pgstat_restart(void) /* ---------- * pgstat_report_tabstat() - * - * Called from tcop/postgres.c to send the so far collected - * per table access statistics to the collector. + * Called from tcop/postgres.c to send the so far collected per-table + * access statistics to the collector. Note that this is called only + * when not within a transaction, so it is fair to use transaction stop + * time as an approximation of current time. * ---------- */ void pgstat_report_tabstat(void) { + static TimestampTz last_report = 0; + TimestampTz now; + + /* Don't expend a clock check if nothing to do */ + if (RegularTabStat.tsa_used == 0 && + SharedTabStat.tsa_used == 0) + return; + + /* + * Don't send a message unless it's been at least PGSTAT_STAT_INTERVAL + * msec since we last sent one. + */ + now = GetCurrentTransactionStopTimestamp(); + if (!TimestampDifferenceExceeds(last_report, now, PGSTAT_STAT_INTERVAL)) + return; + last_report = now; + /* - * For each message buffer used during the last query set the header + * For each message buffer used during the last queries, set the header * fields and send it out; then mark the entries unused. */ pgstat_report_one_tabstat(&RegularTabStat, MyDatabaseId); |
