Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c3p0: what does `maxIdleTime` really mean?

Tags:

database

c3p0

in c3p0, maxIdleTime means:

maxIdleTime: (Default: 0) Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire.

I don't get it. Let's say, if there are 10 awaiting connections in the connection pool, and after maxIdleTime has passed, there are still no new database requests, then all these connections should be discarded? then there will be 0 awaiting connections in the pool?

like image 380
lily Avatar asked Dec 21 '25 15:12

lily


2 Answers

If there are 10 Connections in the pool and no activity, then after maxIdleTime has passed, yes, they will all be expired.

But that does not mean there will be no Connections left in the pool. At the same time as the pool expires old Connections, it will acquire begin new Connections from the DBMS in order to uphold the minPoolSize configuration parameter.

like image 111
Steve Waldman Avatar answered Dec 23 '25 04:12

Steve Waldman


If you have kept a large pool size (i.e. greater than what you anticipate as 99th percentile load), this will mean that you will have lots of idle connections lying around and it is better to clean them up periodically via maxIdleTime and idleConnectionTestPeriod parameter

May be, you will need to add too idleConnectionTestPeriod and preferredTestQuery be sure that connection are valid or not

like image 43
zaarour Avatar answered Dec 23 '25 06:12

zaarour