From: Daniele Varrazzo Date: Thu, 11 Mar 2021 14:31:55 +0000 (+0100) Subject: Don't use a worker in pool.putconn() if not needed X-Git-Tag: 3.0.dev0~87^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8b9a7f1559dcb13d643b35a26d58049e20933cd;p=thirdparty%2Fpsycopg.git Don't use a worker in pool.putconn() if not needed If _reset is not set there is little work to do so the overhead of a context switch is measurable and not necessary. --- diff --git a/psycopg3/psycopg3/pool/async_pool.py b/psycopg3/psycopg3/pool/async_pool.py index 451033a2b..4233938b0 100644 --- a/psycopg3/psycopg3/pool/async_pool.py +++ b/psycopg3/psycopg3/pool/async_pool.py @@ -217,7 +217,10 @@ class AsyncConnectionPool(BasePool[AsyncConnection]): return # Use a worker to perform eventual maintenance work in a separate thread - self.run_task(ReturnConnection(self, conn)) + if self._reset: + self.run_task(ReturnConnection(self, conn)) + else: + await self._return_connection(conn) async def close(self, timeout: float = 5.0) -> None: """Close the pool and make it unavailable to new clients. diff --git a/psycopg3/psycopg3/pool/pool.py b/psycopg3/psycopg3/pool/pool.py index 741c57bc8..12604846e 100644 --- a/psycopg3/psycopg3/pool/pool.py +++ b/psycopg3/psycopg3/pool/pool.py @@ -228,7 +228,10 @@ class ConnectionPool(BasePool[Connection]): return # Use a worker to perform eventual maintenance work in a separate thread - self.run_task(ReturnConnection(self, conn)) + if self._reset: + self.run_task(ReturnConnection(self, conn)) + else: + self._return_connection(conn) def close(self, timeout: float = 1.0) -> None: """Close the pool and make it unavailable to new clients.