Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

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)

question from:https://stackoverflow.com/questions/9451818/what-is-the-difference-between-maxactive-vs-maxidle-for-tomcat-connection-pools

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...