-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to pool to do scheduled connection validation #169
Comments
@ifindya There is already such functionality. Can you try this configuration? reactor-pool/reactor-pool/src/main/java/reactor/pool/PoolBuilder.java Lines 227 to 249 in 574c24b
|
Thank you so much. I have had a look. background tasks are used to evict idle connections and do not keep the connection active, sometimes needing to contain minIdle idle connections in the connection pool at all times until the pool shutdown, in other words, idle connections are exempt from eviction. Did I get that right? |
@ifindya Yes correct. For example in Reactor Netty the connection pool has these settings: max idle time, max life time, active/closed connection. If the connection pool supports warm up then after the eviction, if the pool needs to be filled again with fresh connections then this will be performed. |
@violetagg That's to say Reactor Pool doesn't have these settings and might not warm up after the eviction, right? If so, is there a plan about supporting this? |
On the contrary - everything as infrastructure/configurations is there, the library that uses Reactor Pool needs to use/configure them. For example, Reactor Netty configures Reactor Pool like this: So if background task is enabled the connections will be checked for idle time, life time and whether they are closed. Reactor Netty does not have configuration for warm up, but if the library that uses Reactor Pool enables the configuration for warm up then the pool will be filled with fresh resources. |
All right, then the implementations should be allowed to extend the background task and determine its behavior. Is there such an ability now? |
Reactor Pool invokes only the eviction predicate. There is nothing else interesting in the background task.
The library that uses Reactor pool needs to provide eviction predicate. |
Got it, thanks. |
In r2dbc-pool, when checking whether a connection is valid, a call to the database is made which might take a while. Does reactor-pool ensure that during the eviction check, the pool object (in this case, r2dbc connection) which is being checked for eviction will not be used concurrently by the pool? Also, how to enable the configuration for warmup? |
yes
reactor-pool/reactor-pool/src/main/java/reactor/pool/PoolBuilder.java Lines 346 to 362 in 574c24b
|
I am sorry we're not on the same page before. The library depends on Reactor pool uses eviction predicate to check whether connection is valid and that would require obtaining the connection from the pool, testing it, and removing it from the pool if invalid, thus connection validation might be a remote call(saying to send a message to server side) in non-block way and BiPredicate is incompatible. It seems that there is only one way that will be performed after the eviction is to provide DestoryHandler, which allows users to have effects on the pool from the outside. Therefore, it's not exactly a walk in the park to combine background eviction and warm up. Thanks for your reply in advance. |
Provide the kind of functionality that the connection validation is periodically run in the background.
Motivation
Typically, idle connections will become invalid due to timeouts, network side, or the other cause, in which case we potentially would have to retry the acquirement of the whole pool size of connections when performing a database call and it would be even worse if no valid connections exist which would result to re-warmup the pool. That can significantly increase the time of database calls, which could have been avoided if the connection validation was periodically run in the background.
Desired solution
Checking for each connection periodically if it has exceeded its saying maxIdleTime, also check for each connection whether it is valid or not. Also, after the checks, the connection pool should be re-warmuped, so that it contains at least minIdle connections. Some popular libraries like HikariCP (keepaliveTime) and C3P0 (idleConnectionTestPeriod) and Druid(keepAlive) have this feature, which could be referenced.
Considered alternatives
Additional context
The text was updated successfully, but these errors were encountered: