[PATCH 2 of 7 cubicweb] [database/pool] close connections when load is low

Philippe Pepiot philippe.pepiot at logilab.fr
Tue Jan 14 11:15:36 CET 2020


On 20/12/2019, Laurent Peuch wrote:
> # HG changeset patch
> # User Laurent Peuch <cortex at worlddomination.be>
> # Date 1576829177 -3600
> #      Fri Dec 20 09:06:17 2019 +0100
> # Node ID 33d74a5f647e9cd48f010bf510a10527b2eabe6b
> # Parent  5a2814328fecdc00c41514b8dd5733c8610fee81
> # Available At https://hg.logilab.org/users/lpeuch/cubicweb
> #              hg pull https://hg.logilab.org/users/lpeuch/cubicweb -r 33d74a5f647e
> [database/pool] close connections when load is low
> 
> The logic is to close connection one by one if we didn't had to wait to grab a
> connection and that last time we had to wait a lot was some time ago (assuming
> then that the load is now low).

Not sure I perfectly understand the algorithm you proposed. But by
looking at the pgbouncer code https://github.com/pgbouncer/pgbouncer ,
seem a better algorithm could be:

Use a queue.LifoQueue() instead of default FIFO queue. So a few
connections get the more load. I think it's better on postgresql
side for buffers / caches that belong to the connection.

Then the end of the queue in case of low load will have increasing IDLE time and you can just close them when IDLE is more than X seconds.

What do you think ?



More information about the cubicweb-devel mailing list