-
Notifications
You must be signed in to change notification settings - Fork 873
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
pgxpool: acquire wait time stats #1669
Comments
If this is to be done, at least some of the change should be done in the puddle library. Getting the time is cheap, but not free, and it is already done internally in the puddle acquire logic. It might make sense to add a field to Then the changes in pgxpool would be smaller as well. |
What we do is a bit hacky but essentially: cfg.BeforeAcquire = func(ctx context.Context, c *pgx.Conn) bool {
t, ok := ctx.Value(contextKeyAcquired).(*time.Time)
if ok {
*t = time.Now()
}
return true
}
...
var acquired time.Time
ctx = context.WithValue(ctx, contextKeyAcquired, &acquired)
now := time.Now()
pool.Exec(ctx, ...)
waiting := acquired.Sub(now) |
So even with both the above PRs, we would still not be able to get a histogram of how much time it took to acquire the connection, right? I am not very well versed with pgx code base, but can we leverage acquire tracer to do this?
It seems like passing the start time in context in TraceAcquireStart and reading in TraceAcquireEnd and registering in a histogram would work? |
Is your feature request related to a problem? Please describe.
I'd like to better understand the impact of a fully utilized connection pool. That is the case when there is no idle connections and app tries to acquire one.
There is
Stat.EmptyAcquireCount
, which is a good start, but it doesn't give full picture. I'd like to be able to get a histogram of times app waited for connectionDescribe the solution you'd like
Histogram could be taken if there were
OnAcquireStart
andOnAcquireComplete
, which are called as the very first and very last operation inPool.Acquire
. Alternatively pgxpool could expose histogram in theStat
.Describe alternatives you've considered
Creting own wrapper around
Pool.Acquire
func, but this requires changing all call-sites in the app.Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: