Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 872
ams Avatar asked Feb 26 '12 09:02

ams


People also ask

What is maxIdle in Tomcat?

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. (

What is maxActive in context XML?

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

How many connection pools should I have?

The number of connections in the connection pool should be equal the number of the exec threads configured in WebLogic. The rationale is very simple: If the number of the connections is less than the number of threads, some of the thread maybe waiting for a connection thus making the connection pool a bottleneck.

Which is the best connection pooling in Java?

After going through all the resources, tomcat JDBC and HikariCP seem to be reliable and faster than other two connection pools.


2 Answers

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.

like image 109
souser Avatar answered Oct 09 '22 04:10

souser


maxActive

the maximum number of active connections that can be allocated from this pool at the same time.   

This attribute is used to limit the number of connections a pool can have open.

maxIdle

(int) The maximum number of connections that should be kept in the pool **at all times.**  

This is to limit the idle connections. The connections(not larger than the value of maxIdle) will not be released so that the next request for connections will be much faster.

So in a word, maxActive is to limit max connections.

But idle(maxIdle or minIdle) is more for performance issue(exchange time with space/resources) , among which, the maxIdle is to limit the max connections(the resources) that you are going to exchange time with.

like image 30
JaskeyLam Avatar answered Oct 09 '22 04:10

JaskeyLam