[PATCH 4 of 9 cubicweb] [server] use a LifoQueue in _CnxSetPool

Philippe Pepiot ph at itsalwaysdns.eu
Tue Mar 31 18:38:06 CEST 2020


On 31/03/2020, Philippe Pepiot wrote:
> # HG changeset patch
> # User Philippe Pepiot <ph at itsalwaysdns.eu>
> # Date 1585575002 -7200
> #      Mon Mar 30 15:30:02 2020 +0200
> # Node ID f08a3c909bfaaef5c07376ffc23d35987a33b5c3
> # Parent  0dca6687fcf5fd2754da447856360c365d8d15c2
> # Available At https://philpep.org/pub/hg/cubicweb
> #              hg pull https://philpep.org/pub/hg/cubicweb -r f08a3c909bfa
> [server] use a LifoQueue in _CnxSetPool
> 
> In postgresql, some cache is attached to the connection. Using a LifoQueue
> (last-in, first-out) makes a few connections to get the most load which give
> best performance.
> 
> diff --git a/cubicweb/server/repository.py b/cubicweb/server/repository.py
> --- a/cubicweb/server/repository.py
> +++ b/cubicweb/server/repository.py
> @@ -173,7 +173,7 @@ class _CnxSetPool(_BaseCnxSet):
>      def __init__(self, source, size):
>          super().__init__(source)
>          self._cnxsets = []
> -        self._queue = queue.Queue()
> +        self._queue = queue.LifoQueue()

There is a side effect error with this patch when running "cubicweb-ctl
db-create" on postgresql:

psycopg2.InterfaceError: cursor already closed

This runs fine with sqlite.

There's a bug somewhere. I think cubicweb, somewhere in database
creation code, close the cursor. And since we used a Queue, it was not
getting the closed connection in following repo.cnxsets.get() call. Now
we get the closed connection.

I cannot take a look before next week, so if someone get inspired by
this...

>  
>          for i in range(size):
>              self._queue.put_nowait(self._new_cnxset())

-- 
https://itsalwaysdns.eu



More information about the cubicweb-devel mailing list