Idle connections thrash when pool min > 0 (i.e. by default)
See original GitHub issueI was going to raise this against generic-pool-redux, but I’m not sure if it’s not perhaps an issue with a missing config option here in knex.
The default minimum pool size in knex is 2, so by default 2 connections are kept active at all times. At the same time, there is an idle timeout set to 30 seconds in generic-pool-redux, which cleans away idle connections.
The result is that by default connections are opened and closed every 30 seconds whenever a client is idle. This isn’t much of an issue, until you start scaling the number of clients talking to a database. Then the thrashing LOGN & QUIT requests activating and deactivating idle connections starts blocking real requests from being able to access the database.
Setting min:0
stops the thrashing, but I don’t think this behaviour is correct, especially not as the default behaviour for the library.
Perhaps there is or should be a way to stop idle connections from being cleaned away when there is a min > 0, or perhaps the default min should be 0?
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (10 by maintainers)
Top GitHub Comments
I think this has become an issue again with the switch to generic-pool for pooling as of 0.12.0. We definitely see it with 0.12.9.
edit: We were able to resolve it by add
refreshIdle: false
to the configOk cool, so the default changed - that’s a good start. I also went and read the pool2 docs and they say this:
This sounds like the logic in pool2 will result in much better behaviour. Thanks for the info!