Re: pgstat_send_connstats() introduces unnecessary timestamp and UDP overhead
Kyotaro Horiguchi <horikyota.ntt@gmail.com>
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: laurenz.albe@cybertec.at
Cc: andres@anarazel.de, magnus@hagander.net, pgsql-hackers@postgresql.org
Date: 2021-08-25T01:12:41Z
Lists: pgsql-hackers
At Tue, 24 Aug 2021 12:34:25 +0200, Laurenz Albe <laurenz.albe@cybertec.at> wrote in > On Tue, 2021-08-24 at 15:12 +0900, Kyotaro Horiguchi wrote: > > > > - remove redundant gettimeofday(). > > - avoid sending dedicate UCP packet for connection stats. > > Thank you. > > Perhaps I misread that, but doesn't that mean that the session statistics > could be sent several times? "pgstat_send_tabstat()" could be called more than > once, right? Yes, it can be called two or more times for a call to pgstat_report_stat, but the patch causes only the first of them convey effective connection stats numbers. This is the same way as how transaction stats are treated. If no table activities have taken place at all, pgStatXactCommit/Rollback are not consumed then the following condition: > /* > * Send partial messages. Make sure that any pending xact commit/abort > * gets counted, even if there are no table stats to send. > */ > if (regular_msg.m_nentries > 0 || > pgStatXactCommit > 0 || pgStatXactRollback > 0) leads to a call to pgstat_send_tabstat() and it sends a tabstat message without a table stats, which is a "partial message". In this logic the condition term (pgStatXactCommit > 0 || pgStatXactRollback > 0) acts as a single-shot trigger. So we can piggy-back on the condition to send something only once. The patch sets "0" = (DISCONNECT_NOT_YET) to m_disconnect as the "not-effective" number, but it would be better to add DISCONNECT_something to express that state. regards. -- Kyotaro Horiguchi NTT Open Source Software Center
Commits
-
Fix performance regression from session statistics.
- 7890a423470b 14.0 landed
- 37a9aa659111 15.0 landed
-
Add pg_stat_database counters for sessions and session time
- 960869da0803 14.0 cited