mirror of
https://github.com/simonw/datasette.git
synced 2026-10-18 23:36:57 +02:00
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:
parent
791ce7a3d9
commit
d95b5e70be
1 changed files with 12 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue