A blog about software development, primarily in Java and about web applications.

Friday, January 15, 2010

Apache Tomcat DBCP Connection Pooling

I've been looking at some performance issues with our Tomcat servers (we have many) and have seen some real inconsistency in the DBCP options that are specified. In general the basic ones you'd expect to see are there: a validation query, minIdle, maxActive. However, other ones are missing. This page http://commons.apache.org/dbcp/configuration.html lists the options and gives a good explanation of each. Everyone using Tomcat and DBCP should review this list and understand them.

A couple of interesting options to point out are those dealing with the validity of idle connections in the pool:

testWhileIdle (default false)
The indication of whether objects will be validated by
the idle object evictor (if any). If an object fails to
validate, it will be dropped from the pool. NOTE - for
a true value to have any effect, the validationQuery
parameter must be set to a non-null string.


timeBetweenEvictionRunsMillis (default -1)
The number of milliseconds to sleep between runs of the
idle object evictor thread. When non-positive, no idle
object evictor thread will be run.


numTestsPerEvictionRun (default 3)

The number of objects to examine during each run of the
idle object evictor thread (if any).


minEvictableIdleTimeMillis (default 1000 * 60 * 30)

The minimum amount of time an object may sit idle in
the pool before it is eliga


A good blog post on Apache DBCP can be found on Roy's Musings under Gotchas with DBCP.

For a comparison of Apache DBCP with another connection pool see Vigil Bose's Blog.

Also check out BoneCP for a connection pool specifically written to be fast.

No comments: