Re: pgstat_send_connstats() introduces unnecessary timestamp and UDP overhead - Mailing list pgsql-hackers
From | Andres Freund |
---|---|
Subject | Re: pgstat_send_connstats() introduces unnecessary timestamp and UDP overhead |
Date | |
Msg-id | 20210817091420.u3vgqjh43lnpjntk@alap3.anarazel.de Whole thread Raw |
In response to | Re: pgstat_send_connstats() introduces unnecessary timestamp and UDP overhead (Laurenz Albe <laurenz.albe@cybertec.at>) |
Responses |
Re: pgstat_send_connstats() introduces unnecessary timestamp and UDP overhead
Re: pgstat_send_connstats() introduces unnecessary timestamp and UDP overhead |
List | pgsql-hackers |
Hi, On 2021-08-17 10:44:51 +0200, Laurenz Albe wrote: > On Sun, 2021-08-01 at 13:55 -0700, Andres Freund wrote: > > We maintain last_report as GetCurrentTransactionStopTimestamp(), but then use > > a separate timestamp in pgstat_send_connstats() to compute the difference from > > last_report, which is then set to GetCurrentTransactionStopTimestamp()'s > > return value. > > Makes sense to me. How about passing "now", which was just initialized from > GetCurrentTransactionStopTimestamp(), as additional parameter to > pgstat_send_connstats() and use that value instead of taking the current time? Yes. > > I'm also not all that happy with sending yet another UDP packet for this. This > > doubles the UDP packets to the stats collector in the common cases (unless > > more than TABSTAT_QUANTUM tables have stats to report, or shared tables have > > been accessed). We already send plenty of "summary" information via > > PgStat_MsgTabstat, one of which is sent unconditionally, why do we need a > > separate message for connection stats? > > Are you suggesting that connection statistics should be shoehorned into > some other statistics message? That would reduce the number of UDP packets, > but it sounds ugly and confusing to me. That ship already has sailed. Look at struct PgStat_MsgTabstat typedef struct PgStat_MsgTabstat { PgStat_MsgHdr m_hdr; Oid m_databaseid; int m_nentries; int m_xact_commit; int m_xact_rollback; PgStat_Counter m_block_read_time; /* times in microseconds */ PgStat_Counter m_block_write_time; PgStat_TableEntry m_entry[PGSTAT_NUM_TABENTRIES]; } PgStat_MsgTabstat; Given that we transport number of commits/commits, block read/write time adding the time the connection was active/inactive doesn't really seem like it makes things meaningfully worse? > > Alternatively we could just not send an update to connection stats every 500ms > > for every active connection, but only do so at connection end. The database > > stats would only contain stats for disconnected sessions, while the stats for > > "live" connections are maintained via backend_status.c. That'd give us *more* > > information for less costs, because we then could see idle/active times for > > individual connections. > > That was my original take, but if I remember right, Magnus convinced me that > it would be more useful to have statistics for open sessions as well. > With a connection pool, connections can stay open for a very long time, > and the accuracy and usefulness of the statistics would become questionable. That's not a contradiction to what I propose. Having the data available via backend_status.c allows to sum up the data for active connections and the data for past connections. I think it's also just cleaner to not constantly report changing preliminary data as pgstat_send_connstats() does. > > That'd likely be more change than what we would want to do at this point in > > the release cycle though. But I think we ought to do something about the > > increased overhead... > > If you are talking about the extra GetCurrentTimestamp() call, and my first > suggestion is acceptable, that should be simple. Doubling the number of UDP messages in common workloads seems also problematic enough that it should be addressed for 14. It increases the likelihood of dropping stats messages on busy systems, which can have downstream impacts. Greetings, Andres Freund
pgsql-hackers by date: