Skip to content

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
Fixes #913

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.
* 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.

@JelteF JelteF merged commit 8d16ca3 into pgbouncer:master May 16, 2024
@jcoleman
Copy link
Contributor Author

@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.

@JelteF JelteF mentioned this pull request Jun 27, 2024
sxd added a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 8, 2024
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>
sxd added a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 9, 2024
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>
leonardoce pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 9, 2024
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>
leonardoce pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 9, 2024
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>
cnpg-bot pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 9, 2024
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)
cnpg-bot pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 9, 2024
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)
samtoxie pushed a commit to samtoxie/cloudnative-pg that referenced this pull request Aug 28, 2024
…-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>
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