Repository navigation
Replies: 1 comment
|
The subtraction in (2) gives false positives. For example, with 10 - 5 - 5 == 0 # reports exhaustion, although nothing is borrowedThe established borrowed count is
There isn't a public pool-exhaustion callback in the current API. To avoid polling, measure acquisitions at the call site: from contextlib import asynccontextmanager
import logging
from time import perf_counter
@asynccontextmanager
async def measured_acquire(pool):
start = perf_counter()
async with pool.acquire() as connection:
elapsed = perf_counter() - start
if elapsed >= 0.05: # choose a threshold for your workload
logging.warning("Pool acquisition took %.3fs", elapsed)
yield connectionUse I checked the getter arithmetic and queue boolean behavior with asyncpg 0.32.0, including a pool initialized without connecting to PostgreSQL; I did not run a database/load test. The relevant public getters and acquisition path are in |
Uh oh!
There was an error while loading. Please reload this page.
I have an application that should never exhaust its connection pool.
If it does, I would like to print a warning.
exhausted = _pool.get_max_size() - self._pool.get_size() - self._pool.get_idle_size() == 0or should I just doexhausted = not(_pool._queue),One way of implementing this would be to check if the queue is empty here before calling get() here https://github.com/MagicStack/asyncpg/blob/master/asyncpg/pool.py#L828 and incrementing a counter if it is empty.
It would not be 100% correct, I assume, but it would still be more accurate then polling?
All reactions