From: Daniele Varrazzo Date: Fri, 12 Mar 2021 14:40:49 +0000 (+0100) Subject: Change pool stat requests_timeout to requests_errors, include queue full X-Git-Tag: 3.0.dev0~87^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84205f6773a58f85b24f53a0887b67758928a897;p=thirdparty%2Fpsycopg.git Change pool stat requests_timeout to requests_errors, include queue full --- diff --git a/docs/advanced/pool.rst b/docs/advanced/pool.rst index f79075562..9a907726c 100644 --- a/docs/advanced/pool.rst +++ b/docs/advanced/pool.rst @@ -221,7 +221,8 @@ Metric Meaning ``requests_queued`` Number of requests queued because a connection wasn't immediately available in the pool ``requests_wait_ms`` Total time in the queue for the clients waiting - ``requests_timeouts`` Number of waiting clients whose request timed out + ``requests_errors`` Number of connection requests resulting in an error + (timeouts, queue full...) ``returns_bad`` Number of connections returned to the pool in a bad state ``connections_num`` Number of connection attempts made by the pool to the diff --git a/psycopg3/psycopg3/pool/async_pool.py b/psycopg3/psycopg3/pool/async_pool.py index 5cb14c846..0a3e904d3 100644 --- a/psycopg3/psycopg3/pool/async_pool.py +++ b/psycopg3/psycopg3/pool/async_pool.py @@ -134,6 +134,7 @@ class AsyncConnectionPool(BasePool[AsyncConnection]): self._nconns_min = len(self._pool) else: if self.max_waiting and len(self._waiting) >= self.max_waiting: + self._stats[self._REQUESTS_ERRORS] += 1 raise TooManyRequests( f"the pool {self.name!r} has aleady" f" {len(self._waiting)} requests waiting" @@ -163,7 +164,7 @@ class AsyncConnectionPool(BasePool[AsyncConnection]): try: conn = await pos.wait(timeout=timeout) except Exception: - self._stats[self._REQUESTS_TIMEOUTS] += 1 + self._stats[self._REQUESTS_ERRORS] += 1 raise finally: t1 = monotonic() diff --git a/psycopg3/psycopg3/pool/base.py b/psycopg3/psycopg3/pool/base.py index 919ffce8b..664c07d1d 100644 --- a/psycopg3/psycopg3/pool/base.py +++ b/psycopg3/psycopg3/pool/base.py @@ -33,7 +33,7 @@ class BasePool(Generic[ConnectionType]): _REQUESTS_NUM = "requests_num" _REQUESTS_QUEUED = "requests_queued" _REQUESTS_WAIT_MS = "requests_wait_ms" - _REQUESTS_TIMEOUTS = "requests_timeouts" + _REQUESTS_ERRORS = "requests_errors" _USAGE_MS = "usage_ms" _RETURNS_BAD = "returns_bad" _CONNECTIONS_NUM = "connections_num" diff --git a/psycopg3/psycopg3/pool/pool.py b/psycopg3/psycopg3/pool/pool.py index f24f3b9f9..691b777fc 100644 --- a/psycopg3/psycopg3/pool/pool.py +++ b/psycopg3/psycopg3/pool/pool.py @@ -177,6 +177,7 @@ class ConnectionPool(BasePool[Connection]): self._nconns_min = len(self._pool) else: if self.max_waiting and len(self._waiting) >= self.max_waiting: + self._stats[self._REQUESTS_ERRORS] += 1 raise TooManyRequests( f"the pool {self.name!r} has aleady" f" {len(self._waiting)} requests waiting" @@ -207,7 +208,7 @@ class ConnectionPool(BasePool[Connection]): try: conn = pos.wait(timeout=timeout) except Exception: - self._stats[self._REQUESTS_TIMEOUTS] += 1 + self._stats[self._REQUESTS_ERRORS] += 1 raise finally: t1 = monotonic() diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 45162d43c..93a59ad82 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -323,6 +323,7 @@ def test_queue_size(dsn): assert isinstance(errors[0], pool.TooManyRequests) assert p.name in str(errors[0]) assert str(p.max_waiting) in str(errors[0]) + assert p.get_stats()["requests_errors"] == 1 @pytest.mark.slow @@ -919,7 +920,7 @@ def test_stats_usage(dsn): assert stats["requests_num"] == 7 assert stats["requests_queued"] == 4 assert 850 <= stats["requests_wait_ms"] <= 950 - assert stats["requests_timeouts"] == 1 + assert stats["requests_errors"] == 1 assert 1150 <= stats["usage_ms"] <= 1250 assert stats.get("returns_bad", 0) == 0 diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 5c9ca80be..d360f002f 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -339,6 +339,7 @@ async def test_queue_size(dsn): assert isinstance(errors[0], pool.TooManyRequests) assert p.name in str(errors[0]) assert str(p.max_waiting) in str(errors[0]) + assert p.get_stats()["requests_errors"] == 1 @pytest.mark.slow @@ -916,7 +917,7 @@ async def test_stats_usage(dsn): assert stats["requests_num"] == 7 assert stats["requests_queued"] == 4 assert 850 <= stats["requests_wait_ms"] <= 950 - assert stats["requests_timeouts"] == 1 + assert stats["requests_errors"] == 1 assert 1150 <= stats["usage_ms"] <= 1250 assert stats.get("returns_bad", 0) == 0