5

I understand from reading HikariCP's documentation (see below) that idle connections should be retired from a connection pool.

My question is: why and when should an idle database connection be retired from the connection pool?

This is the part of HikariCP documentation that sparked my question:

idleTimeout:

This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30 seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout. A value of 0 means that idle connections are never removed from the pool. Default: 600000 (10 minutes)

1 Answer 1

5

Two main reasons:

a) they take up resources on the server (not terribly much since the connection is idle)

b) sometimes connections timeout themselves after periods of inactivity. You want to either close them before that, or run some periodic "ping" SQL to make sure they are still alive. Otherwise you'd get an error on the next SQL you want to execute.

Sign up to request clarification or add additional context in comments.

1 Comment

Note on b: HikariCP does a ping before returning a connection from the pool, if the ping indicates an invalid connection, the next connection from the pool is fetched, etc.. So even if there are connections in the pool that have timed out, the application should not receive these connections from the pool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.