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
Make avg_wait_time a meaningful metric #727
base: master
Are you sure you want to change the base?
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
@@ -235,6 +235,7 @@ int pga_cmp_addr(const PgAddr *a, const PgAddr *b); | |||
* 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.
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. |
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