title: Tomcat Datasource configuration Connection timeout and Max Active to Idle connection ratio
body: <p>I am having a web application which is load balanced on four servers. These three servers connect to common database with max connections setup to 600. </p>
  
  <p>My Current database pool configuration in tomcat is as follows: </p>
  
  <pre><code>&lt;Resource name="jdbc/AppDB"
                            auth="Container"
                            type="javax.sql.DataSource"
                            maxActive="100"
                            maxIdle="30"
                            maxWait="10000"
                            removeAbandoned ="true"
                            removeAbandonedTimeout="300"
                            testOnBorrow="true"
                            validationQuery="select 1"
                            logAbandoned ="true"
                            username="username"
                            password="password"
                            driverClassName="com.mysql.jdbc.Driver"
                            url="dbconnectionurl"
                   /&gt;
  </code></pre>
  
  <p>But this configuration gives Exception: <code>Connection Timeout : Waiting for Idle Object.</code> </p>
  
  <p>I have monitored database server, my effective utilization of connections is 350 only. </p>
  
  <p>If I calculate it backwards, I have total 400 connections used actively. This gives me 200 extra database connections available from DB. </p>
  
  <p>Hence, I am not able to understand why this Exception is coming. </p>
  
  <p>Can anybody suggest a better configuration ? 
  What should be the ideal ratio of <code>maxActive</code> and <code>maxIdle</code> ? </p>
  
  <p>UPDATE:</p>
  
  <p>I found a related link: 
  <a href="https://stackoverflow.com/questions/15735429/there-are-not-enough-idle-connections-in-tomcat-jdbc-pool?rq=1">There are not enough idle connections in Tomcat JDBC pool</a></p>
  
  <p>But I can not risk setting maxIdle or MaxActive to -1(INFINITE) because I have multiple instances running, and it might make uneven distribution of connections. This may cause one instance to perform nicely and other may fail due to lack of connections.</p>