Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jcoleman
Copy link
Contributor

@jcoleman jcoleman commented Jun 17, 2022

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

jcoleman added 3 commits June 15, 2022 20:06
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.
@@ -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;
Copy link
Member

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?

Copy link
Member

@JelteF JelteF Oct 13, 2023

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.

Copy link
Member

@JelteF JelteF left a 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.

@JelteF JelteF self-requested a review May 8, 2024 10:34
@JelteF
Copy link
Member

JelteF commented May 8, 2024

I made the changes I wanted from this PR and pushed them to your branch. Barring objections, I'll probably merge this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Average Wait time / Units
2 participants