r2dbc / r2dbc-pool

Connection Pooling for Reactive Relational Database Connectivity
https://r2dbc.io
Apache License 2.0
332 stars 55 forks source link

Support configuration of minimum idle connections #141

Closed mostafavahidi closed 2 years ago

mostafavahidi commented 2 years ago

Hi all,

Recently, my team has come across an issue where number of connections in the connection pool drops to 0 after some time that the pool is not used. We want to be able to set some property in r2dbc-pool that allows us to keep a minimum number of idle connections regardless of the usage of the pool.

After some searching, I found that the apache DBCP library offers minIdle setting: https://commons.apache.org/proper/commons-dbcp/configuration.html minIdle: The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.

Unfortunately, in r2dbc-pool, I haven't found a similar param. The following two params are similar but look like they would change the lifecycle behavior of the pool itself: backgroundEvictionInterval & maxIdleTime

They're not quite what we're after. Is there a solution/hack that I can do that will allow me to set the minimum number of idle connections I want to keep at all times that I am missing?

If not, are there any plans that this will be added in the future?

Thank you for response, Mostafa

mp911de commented 2 years ago

You can use initialSize and ConnectionPool.warmup() to instruct the pool to create initialSize of connections. There's no way to keep a number of additional connections around that increased with each allocation. Reactor Pool allows for a AllocationStrategy but we do not accept allocation strategies to keep the configuration simple.

I wonder whether you could simply call warmup() periodically (e.g. through a Scheduler) to ensure a number of connections in the pool.

We have seen recently a number of reports (e.g. #140) that the connection pool connections deplete due to some improper connection releases. Mostly FYI, but that might play into this report as well.

jonenst commented 2 years ago

Hi, I would like to have a similar feature. It seems like a very common requirement. For example HikariCP has it too. Do we need to open a bug report in reactor pool to allow r2dbc-pool to implement a minimum number of connections that are never closed, even if idle ?

mp911de commented 2 years ago

That's in place now. InitialSize is somewhat overlapping, if both values are configured, we're going to use the greater one.

grantas33 commented 1 year ago

Currently, after maxIdleTime has passed all idle connections close and minIdle field does not have any effect. Is this a bug or expected behavior? I would expect that at least minIdle number of connections should never be closed.