-
Notifications
You must be signed in to change notification settings - Fork 528
Make avg_wait_time a meaningful metric #727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Currently avg_wait_time is calculated as the wait time accumulated by clients that were assigned a backend in the current stats_period and averaged over the time in that period. That means that a connection that's been waiting for 10 minutes will cause (assuming the default stats_period of 60s) a reported 10s average wait time in the stats_period it is assigned a connection (10m = 600s then 600s / 60s). It's fairly obvious that's not meaningful, because the reported value has no relation to the wait time experienced by an average client. If we instead keep track of how many times backends have been assigned for the current pool (if we were limited to transaction pooling, we could use transaction count, for example, but we want something that's generic across all pooling modes) then we can report the wait time experienced on average by a client assigned a backend during the current stats period.
include/bouncer.h
Outdated
| * Stats, kept per-pool. | ||
| */ | ||
| struct PgStats { | ||
| uint64_t backend_assignment_count; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this new counter? Isn't xact_count effectively the same as backend_assignment_count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's close but not always the same. Transaction count only gets incremented at the end of the transaction and this gets incremented at the start. So yeah this new counter is needed. I do think we should expose this new counter to users too though, otherwise it's impossible to calculate the total wait time for users.
JelteF
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rebase and preferably also some tests, but other than that I think this is a good change.
|
I made the changes I wanted from this PR and pushed them to your branch. Barring objections, I'll probably merge this next week. |
|
@JelteF Thanks for putting the work in to get this over the finish line as I'd been unable to devote the necessary time to do so. Apologies for my being incommunicado here; I've very happy to see this merged. |
The latest version of pgBouncer added a new metric in this PR pgbouncer/pgbouncer#727 this patch add that metric to the list of exported one and generated by `SHOW STATS` Closes #5043 Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
The latest version of pgBouncer added a new metric in this PR pgbouncer/pgbouncer#727 this patch add that metric to the list of exported one and generated by `SHOW STATS` Closes #5043 Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
The latest version of pgBouncer added a new metric in this PR pgbouncer/pgbouncer#727 this patch add that metric to the list of exported one and generated by `SHOW STATS` Closes #5043 Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
PgBouncer version 1.23.0 adds new columns for the `SHOW STATS` query. This patch exposes them as metrics while retaining backward compatibility with the older versions. Closes #5043 See: pgbouncer/pgbouncer#727 Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
PgBouncer version 1.23.0 adds new columns for the `SHOW STATS` query. This patch exposes them as metrics while retaining backward compatibility with the older versions. Closes #5043 See: pgbouncer/pgbouncer#727 Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> (cherry picked from commit 224ec9b)
PgBouncer version 1.23.0 adds new columns for the `SHOW STATS` query. This patch exposes them as metrics while retaining backward compatibility with the older versions. Closes #5043 See: pgbouncer/pgbouncer#727 Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> (cherry picked from commit 224ec9b)
…-pg#5044) PgBouncer version 1.23.0 adds new columns for the `SHOW STATS` query. This patch exposes them as metrics while retaining backward compatibility with the older versions. Closes cloudnative-pg#5043 See: pgbouncer/pgbouncer#727 Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Signed-off-by: Sam Toxopeus <sam@fuga.cloud>
Currently avg_wait_time is calculated as the wait time accumulated by
clients that were assigned a backend in the current stats_period and
averaged over the time in that period. That means that a connection
that's been waiting for 10 minutes will cause (assuming the default
stats_period of 60s) a reported 10s average wait time in the
stats_period it is assigned a connection (10m = 600s then 600s / 60s).
It's fairly obvious that's not meaningful, because the reported value
has no relation to the wait time experienced by an average client.
If we instead keep track of how many times backends have been assigned
for the current pool (if we were limited to transaction pooling, we
could use transaction count, for example, but we want something that's
generic across all pooling modes) then we can report the wait time
experienced on average by a client assigned a backend during the current
stats period.
As cleanup first (to make sure I understand the stats calculation) I uncovered
and removed dead code (in separate commits).
Fixes #316
Fixes #913