Our 12 and 24 hour stress tests (300 concurrent users inserting lots of data) were running out of memory after about 8+ hours. After some tests we determined that it was DBCP. This determination was made by switching out the commons connection pooling and using an application server (Weblogic 8.1) connection pooling. Using the application server connection pooling memory was not leaked. So doing some debugging with some long running tests in my dev environment (using OptimizeIt), I determined that the KeyedCPDSConnectionFactory.java was leaking memory with the WeakHashMap (class member pcMap). I don't understand why this should leak because the jdk documentation indicates that the keys in the map are weak referenced and when the keys are removed, the object is removed from the map. Nonetheless, I made the following code change (diff is in attachment) and reran my dev tests and no leak occurred and we reran our stress tests in the performance lab and no leak occurred there either. Perhaps some version of the JDK is causing this but I suspect others may run into this as well. Included is a patch that fixed our problem:
<<patch_memleak.txt>>
ToddC
Index: PooledConnectionImpl.java =================================================================== RCS file: /usr/local/cvsrep/javatools/jakarta/commons-dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PooledConnectionImpl.java 11 Feb 2004 19:37:49 -0000 1.3 +++ PooledConnectionImpl.java 3 Mar 2004 00:31:35 -0000 1.4 @@ -1,7 +1,7 @@ /* * $Source: /usr/local/cvsrep/javatools/jakarta/commons-dbcp/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java,v $ - * $Revision: 1.3 $ - * $Date: 2004/02/11 19:37:49 $ + * $Revision: 1.4 $ + * $Date: 2004/03/03 00:31:35 $ * * ==================================================================== * @@ -82,7 +82,7 @@ * PooledConnectionDataSource. * * @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a> - * @version $Id: PooledConnectionImpl.java,v 1.3 2004/02/11 19:37:49 toddc Exp $ + * @version $Id: PooledConnectionImpl.java,v 1.4 2004/03/03 00:31:35 toddc Exp $ */ class PooledConnectionImpl implements PooledConnection, KeyedPoolableObjectFactory { @@ -169,6 +169,7 @@ throw new SQLNestedException("Cannot close connection (return to pool failed)", e); } finally { connection.close(); + connection = null; } } Index: KeyedCPDSConnectionFactory.java =================================================================== RCS file: /usr/local/cvsrep/javatools/jakarta/commons-dbcp/src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- KeyedCPDSConnectionFactory.java 25 Nov 2003 04:50:28 -0000 1.2 +++ KeyedCPDSConnectionFactory.java 3 Mar 2004 00:31:35 -0000 1.3 @@ -1,7 +1,7 @@ /* * $Source: /usr/local/cvsrep/javatools/jakarta/commons-dbcp/src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java,v $ - * $Revision: 1.2 $ - * $Date: 2003/11/25 04:50:28 $ + * $Revision: 1.3 $ + * $Date: 2004/03/03 00:31:35 $ * * ==================================================================== * @@ -83,7 +83,7 @@ * {*link PoolableConnection}s. * * @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a> - * @version $Id: KeyedCPDSConnectionFactory.java,v 1.2 2003/11/25 04:50:28 toddc Exp $ + * @version $Id: KeyedCPDSConnectionFactory.java,v 1.3 2004/03/03 00:31:35 toddc Exp $ */ class KeyedCPDSConnectionFactory implements KeyedPoolableObjectFactory, ConnectionEventListener { @@ -184,7 +184,9 @@ public void destroyObject(Object key, Object obj) throws Exception { if (obj instanceof PooledConnectionAndInfo) { - ((PooledConnectionAndInfo)obj).getPooledConnection().close(); + PooledConnection pc = ((PooledConnectionAndInfo)obj).getPooledConnection(); + pcMap.remove(pc); + pc.close(); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
