What is the difference between maxActive vs. maxIdle for Tomcat connection pools?

ams picture ams · Feb 26, 2012 · Viewed 76.1k times · Source

The tomcat connection pool has a setting called maxActive and a setting called maxIdle my questions are.

  1. What is the difference between these two settings?
  2. What is a real world example scenario where you might have a different value for maxActive than you would for maxIdle?

For some reason the docs are not making sense to me. maxActive and maxIdle exist on both the apache dbcp and the tomact 7 jdbc-pool according to the docs at http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

maxActive (int) The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100

maxIdle (int) The maximum number of connections that should be kept in the pool at all times. Default value is maxActive:100 Idle connections are checked periodically (if enabled) and connections that been idle for longer than minEvictableIdleTimeMillis will be released. (also see testWhileIdle)

Answer

souser picture souser · Feb 26, 2012

maxActive is straight forward. maxIdle can be explained in this way - say you have 100 max Active connections and say you set maxIdle to 80. Assuming there are no requests going to the database, only 80 connections will be tested (via the validationquery) and will stay active. The other 20 will be closed. So at any point you can only have 80 idle connections.
You might want to set this to be a different number to prevent additional (unnecessary) connections going out to the database. Cos every connection that is served by the database consumes resources (like memory).
But, assuming you have set the maxActive size to 100 and all 100 are in use almost all the time, this setting will obviously not matter.