I'm trying to figure out a problem that we have in a high traffic site using Tomcat 6.0.37 and MySQL 5.5 underneath the cover. The test load was 200 concurrent connections to Tomcat - all connections to the same URL and all of them hitting the database.
To do our connection pooling we're using the embedded tomcat-dbcp package. Here's the resource configuration that we use:
<Resource name="jdbc/appDataSource" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/myapp?autoReconnect=true&characterEncoding=UTF-8"
username="root"
password="*****"
testOnBorrow="true"
maxWait="5000"
maxIdle="1"
maxActive="30"
validationQuery="SELECT 1"
validationInterval="30000"
timeBetweenEvictionRunsMillis="30000"
logAbandoned="true"
removeAbandoned="true"
removeAbandonedTimeout="60"
/>
When I run some test traffic on that site I see that the connection pool looses connections pretty extensively. After about a minute I've had over 10000 connection attempts to MySQL and the pool never held more than 20 connections - all of them were almost immediately closed.
I've tried switching to Apache Commons by adding it to the lib folder and including the property
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
in my configuration but it gave me the exact same results.
I tried switching to C3P0 and BoneCP which in fact worked quite nice and I saw the max of 30 connections being held - no new or dropped connections on MySQL
I've also tried using the connection pool from Apache Tomcat 7 (just for the sake of it) and it also worked quite nicely with the following configuration:
<Resource name="jdbc/appDataSource" auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/myapp?autoReconnect=true&characterEncoding=UTF-8"
username="root"
password="******"
maxIdle="1"
maxActive="30"
validationQuery="SELECT 1"
validationInterval="30000"
timeBetweenEvictionRunsMillis="30000"
logAbandoned="true"
removeAbandoned="true"
removeAbandonedTimeout="60"
/>
I wonder if there's something really wrong with Apache Commons DBCP that it doesn't work even in the simplest case? Is there an explanation to all this?