Why HikariCP not support test-while-idle?
My DataBase's wait_timeout : 60s
HikariCP recommends max-lifetime = wait_timeout - 30s
so.. max-lifetime will be 30s.
Is not it dangerous adding new Connection every 30 seconds?
Is there anything I do not know?
Please suggest how to set it up
@pkgonan HikariCP respects Database Administrators. If your DBA has decided that the maximum connection time should be 60s, then running a background test that essentially keeps the connection alive, even if idle, defeats that decision.
I have updated the documentation for maxLifetime:
...it should be several seconds shorter than any database or infrastructure imposed connection time limit.
In previous versions of HikariCP, the maxLifetime was enforced by the housekeeper thread, which runs every 30 seconds, and therefore wait_timeout - 30s was the recommended maxLifetime.
However, recent versions of HikariCP use a dedicated timer task per-connection. This provides a typical resolution of several tens of milliseconds, but under load maybe up to several seconds. It should be safe to set maxLifetime to wait_timeout - 5s.
Regarding performance, connections are retired and added by background threads, and connection creation typically takes several milliseconds. In a connection pool with 10 connections, a retirement/replacement that takes 20ms means a roughly 10% potential impact on performance during a 20ms window of time.
Basically, it would be difficult to measure the impact of connection replacement, even at an aggressive maxLifetime of 55s.
If maxLifetime is 60s, then idleTimeout is unnecessary (I would set it to 0).
Most helpful comment
@pkgonan HikariCP respects Database Administrators. If your DBA has decided that the maximum connection time should be 60s, then running a background test that essentially keeps the connection alive, even if idle, defeats that decision.
I have updated the documentation for
maxLifetime:In previous versions of HikariCP, the
maxLifetimewas enforced by the housekeeper thread, which runs every 30 seconds, and thereforewait_timeout - 30swas the recommendedmaxLifetime.However, recent versions of HikariCP use a dedicated timer task per-connection. This provides a typical resolution of several tens of milliseconds, but under load maybe up to several seconds. It should be safe to set
maxLifetimetowait_timeout - 5s.Regarding performance, connections are retired and added by background threads, and connection creation typically takes several milliseconds. In a connection pool with 10 connections, a retirement/replacement that takes 20ms means a roughly 10% potential impact on performance during a 20ms window of time.
Basically, it would be difficult to measure the impact of connection replacement, even at an aggressive
maxLifetimeof 55s.If
maxLifetimeis 60s, thenidleTimeoutis unnecessary (I would set it to 0).