Pool stats: record longest wait for a connection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwkLo2rJWidpkDVT3HkvNv
This commit is contained in:
Claude 2026-10-04 01:27:40 +00:00
commit d95b5e70be
No known key found for this signature in database

View file

@ -195,6 +195,11 @@ class ReadConnectionPool:
self._collect_expired_locked(now, to_close)
deadline = None
while True:
if deadline is not None:
self.stats["wait_ms_max"] = max(
self.stats["wait_ms_max"],
int((time.monotonic() - now) * 1000),
)
if state.idle:
entry = state.idle.pop()
if state.counted:
@ -227,11 +232,15 @@ class ReadConnectionPool:
self._cond.wait(remaining)
finally:
self._waiters -= 1
self.stats["wait_ms_total"] += int(
(time.monotonic() - t0) * 1000
)
waited_ms = int((time.monotonic() - t0) * 1000)
self.stats["wait_ms_total"] += waited_ms
continue
self.stats["wait_timeouts"] += 1
if deadline is not None:
self.stats["wait_ms_max"] = max(
self.stats["wait_ms_max"],
int((time.monotonic() - now) * 1000),
)
# Soft cap: open one more. Bounded by the number of threads
# that can hold a lease at once (num_sql_threads).
self.stats["exceeded_cap"] += 1