Added in c3p0 to the performance tests, it doesn't even perform as well as DBCP,...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 23 Apr 2009 16:02:32 +0000 (16:02 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 23 Apr 2009 16:02:32 +0000 (16:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@767949 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/.classpath
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java

index fcc2a15..dcff63c 100644 (file)
@@ -7,5 +7,6 @@
        <classpathentry kind="var" path="TOMCAT_LIBS_BASE/tomcat6-deps/dbcp/tomcat-dbcp.jar" sourcepath="/TOMCAT_LIBS_BASE/tomcat6-deps/dbcp/src/java"/>
        <classpathentry kind="lib" path="mysql-connector-java-5.1.6-bin.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="lib" path="c3p0-0.9.1.2.jar" sourcepath="c3p0-0.9.1.2.src.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 2d8abc3..83ba388 100644 (file)
@@ -23,7 +23,6 @@ import java.sql.ResultSet;
 
 import javax.sql.DataSource;
 
-import org.apache.tomcat.jdbc.pool.DataSourceFactory;
 
 /**
  * @author Filip Hanik
@@ -67,7 +66,7 @@ public class CheckOutThreadTest extends DefaultTestCase {
         for (int i=0; i<threadcount; i++) {
             TestThread t = new TestThread();
             t.setName("tomcat-pool-"+i);
-            t.d = DataSourceFactory.getDataSource(this.datasource);
+            t.d = this.datasource;
             t.start();
         }
         latch.await();
@@ -76,6 +75,26 @@ public class CheckOutThreadTest extends DefaultTestCase {
         tearDown();
     }
 
+    public void testC3P0Threads10Connections10() throws Exception {
+        init();
+        this.datasource.getPoolProperties().setMaxActive(10);
+        this.threadcount = 10;
+        this.transferPropertiesToC3P0();
+        this.c3p0Datasource.getConnection().close();
+        latch = new CountDownLatch(threadcount);
+        long start = System.currentTimeMillis();
+        for (int i=0; i<threadcount; i++) {
+            TestThread t = new TestThread();
+            t.setName("tomcat-pool-"+i);
+            t.d = this.c3p0Datasource;
+            t.start();
+        }
+        latch.await();
+        long delta = System.currentTimeMillis() - start;
+        System.out.println("[testC3P0Threads10Connections10]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));
+        tearDown();
+    }
+
     public void testDBCPThreads20Connections10() throws Exception {
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
@@ -107,7 +126,7 @@ public class CheckOutThreadTest extends DefaultTestCase {
         for (int i=0; i<threadcount; i++) {
             TestThread t = new TestThread();
             t.setName("tomcat-pool-"+i);
-            t.d = DataSourceFactory.getDataSource(this.datasource);
+            t.d = this.datasource;
             t.start();
         }
         latch.await();
@@ -128,7 +147,7 @@ public class CheckOutThreadTest extends DefaultTestCase {
         for (int i=0; i<threadcount; i++) {
             TestThread t = new TestThread();
             t.setName("tomcat-pool-"+i);
-            t.d = DataSourceFactory.getDataSource(this.datasource);
+            t.d = this.datasource;
             t.start();
         }
         latch.await();
@@ -137,6 +156,25 @@ public class CheckOutThreadTest extends DefaultTestCase {
         tearDown();
     }
 
+    public void testC3P0Threads20Connections10() throws Exception {
+        init();
+        this.datasource.getPoolProperties().setMaxActive(10);
+        this.threadcount = 20;
+        this.transferPropertiesToC3P0();
+        this.c3p0Datasource.getConnection().close();
+        latch = new CountDownLatch(threadcount);
+        long start = System.currentTimeMillis();
+        for (int i=0; i<threadcount; i++) {
+            TestThread t = new TestThread();
+            t.setName("tomcat-pool-"+i);
+            t.d = this.c3p0Datasource;
+            t.start();
+        }
+        latch.await();
+        long delta = System.currentTimeMillis() - start;
+        System.out.println("[testC3P0Threads20Connections10]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));
+        tearDown();
+    }
     
     public void testDBCPThreads10Connections10Validate() throws Exception {
         init();
@@ -173,7 +211,7 @@ public class CheckOutThreadTest extends DefaultTestCase {
         for (int i=0; i<threadcount; i++) {
             TestThread t = new TestThread();
             t.setName("tomcat-pool-validate-"+i);
-            t.d = DataSourceFactory.getDataSource(this.datasource);
+            t.d = this.datasource;
             t.start();
         }
         latch.await();
@@ -181,6 +219,28 @@ public class CheckOutThreadTest extends DefaultTestCase {
         System.out.println("[testPoolThreads10Connections10Validate]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));
         tearDown();
     }
+    
+    public void testC3P0Threads10Connections10Validate() throws Exception {
+        init();
+        this.datasource.getPoolProperties().setMaxActive(10);
+        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
+        this.datasource.getPoolProperties().setTestOnBorrow(true);
+        this.threadcount = 10;
+        this.transferPropertiesToC3P0();
+        this.c3p0Datasource.getConnection().close();
+        latch = new CountDownLatch(threadcount);
+        long start = System.currentTimeMillis();
+        for (int i=0; i<threadcount; i++) {
+            TestThread t = new TestThread();
+            t.setName("tomcat-pool-validate-"+i);
+            t.d = this.c3p0Datasource;
+            t.start();
+        }
+        latch.await();
+        long delta = System.currentTimeMillis() - start;
+        System.out.println("[testC3P0Threads10Connections10Validate]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));
+        tearDown();
+    }
 
     public void testDBCPThreads20Connections10Validate() throws Exception {
         init();
@@ -217,7 +277,7 @@ public class CheckOutThreadTest extends DefaultTestCase {
         for (int i=0; i<threadcount; i++) {
             TestThread t = new TestThread();
             t.setName("tomcat-pool-validate-"+i);
-            t.d = DataSourceFactory.getDataSource(this.datasource);
+            t.d = this.datasource;
             t.start();
         }
         latch.await();
@@ -226,6 +286,28 @@ public class CheckOutThreadTest extends DefaultTestCase {
         tearDown();
     }
     
+    public void testC3P0Threads10Connections20Validate() throws Exception {
+        init();
+        this.datasource.getPoolProperties().setMaxActive(10);
+        this.datasource.getPoolProperties().setValidationQuery("SELECT 1");
+        this.datasource.getPoolProperties().setTestOnBorrow(true);
+        this.threadcount = 20;
+        this.transferPropertiesToC3P0();
+        this.c3p0Datasource.getConnection().close();
+        latch = new CountDownLatch(threadcount);
+        long start = System.currentTimeMillis();
+        for (int i=0; i<threadcount; i++) {
+            TestThread t = new TestThread();
+            t.setName("tomcat-pool-validate-"+i);
+            t.d = this.c3p0Datasource;
+            t.start();
+        }
+        latch.await();
+        long delta = System.currentTimeMillis() - start;
+        System.out.println("[testC3P0Threads10Connections20Validate]Test complete:"+delta+" ms. Iterations:"+(threadcount*this.iterations));
+        tearDown();
+    }
+
     public class TestThread extends Thread {
         protected DataSource d;
         protected String query = null;
index 3821ff9..251f413 100644 (file)
@@ -19,6 +19,8 @@ package org.apache.tomcat.jdbc.test;
 import java.lang.reflect.Method;
 import java.util.Properties;
 
+import javax.sql.DataSource;
+
 import org.apache.tomcat.dbcp.dbcp.BasicDataSource;
 import org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory;
 
@@ -26,21 +28,24 @@ import junit.framework.TestCase;
 import org.apache.tomcat.jdbc.pool.PoolProperties;
 import org.apache.tomcat.jdbc.pool.DataSourceProxy;
 
+import com.mchange.v2.c3p0.ComboPooledDataSource;
+
 /**
  * @author Filip Hanik
  * @version 1.0
  */
 public class DefaultTestCase extends TestCase {
-    protected DataSourceProxy datasource;
+    protected org.apache.tomcat.jdbc.pool.DataSource datasource;
     protected BasicDataSource tDatasource;
+    protected DataSource c3p0Datasource;
     protected int threadcount = 10;
     protected int iterations = 100000;
     public DefaultTestCase(String name) {
         super(name);
     }
 
-    public DataSourceProxy createDefaultDataSource() {
-        DataSourceProxy datasource = null;
+    public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
+        org.apache.tomcat.jdbc.pool.DataSource datasource = null;
         PoolProperties p = new DefaultProperties();
         p.setJmxEnabled(false);
         p.setTestWhileIdle(false);
@@ -95,6 +100,68 @@ public class DefaultTestCase extends TestCase {
             x.printStackTrace();
         }
     }
+    
+    protected void transferPropertiesToC3P0() throws Exception {
+        System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");
+        //http://www.mchange.com/projects/c3p0/index.html#automaticTestTable
+        ComboPooledDataSource c3p0 = new ComboPooledDataSource();  
+        c3p0.setAcquireIncrement(1);
+        c3p0.setAcquireRetryAttempts(2);
+        c3p0.setAcquireRetryDelay(datasource.getPoolProperties().getMaxWait());
+        c3p0.setCheckoutTimeout(datasource.getPoolProperties().getMaxWait());
+        c3p0.setDebugUnreturnedConnectionStackTraces(datasource.getPoolProperties().isLogAbandoned());
+        c3p0.setIdleConnectionTestPeriod(datasource.getPoolProperties().getTimeBetweenEvictionRunsMillis()/1000);
+        c3p0.setInitialPoolSize(datasource.getPoolProperties().getInitialSize());
+        c3p0.setMaxIdleTime(datasource.getPoolProperties().getMinEvictableIdleTimeMillis()/1000);
+        c3p0.setMaxIdleTimeExcessConnections(datasource.getPoolProperties().getMaxIdle());
+        c3p0.setMaxPoolSize(datasource.getPoolProperties().getMaxActive());
+        c3p0.setMinPoolSize(datasource.getPoolProperties().getMinIdle());
+        c3p0.setPassword(datasource.getPoolProperties().getPassword());
+        c3p0.setPreferredTestQuery(datasource.getPoolProperties().getValidationQuery());
+        c3p0.setTestConnectionOnCheckin(datasource.getPoolProperties().isTestOnReturn());
+        c3p0.setTestConnectionOnCheckout(datasource.getPoolProperties().isTestOnBorrow());
+        c3p0.setUnreturnedConnectionTimeout(datasource.getPoolProperties().getRemoveAbandonedTimeout());
+        c3p0.setUser(datasource.getPoolProperties().getUsername());
+        c3p0.setUsesTraditionalReflectiveProxies(true);
+        c3p0.setJdbcUrl(datasource.getPoolProperties().getUrl());
+        c3p0.setDriverClass(datasource.getPoolProperties().getDriverClassName());
+        this.c3p0Datasource = c3p0;
+      /**
+        acquireIncrement
+        acquireRetryAttempts
+        acquireRetryDelay
+        autoCommitOnClose
+        automaticTestTable
+        breakAfterAcquireFailure
+        checkoutTimeout
+        connectionCustomizerClassName
+        connectionTesterClassName
+        debugUnreturnedConnectionStackTraces
+        factoryClassLocation
+        forceIgnoreUnresolvedTransactions
+        idleConnectionTestPeriod
+        initialPoolSize
+        maxAdministrativeTaskTime
+        maxConnectionAge
+        maxIdleTime
+        maxIdleTimeExcessConnections
+        maxPoolSize
+        maxStatements
+        maxStatementsPerConnection
+        minPoolSize
+        numHelperThreads
+        overrideDefaultUser
+        overrideDefaultPassword
+        password
+        preferredTestQuery
+        propertyCycle
+        testConnectionOnCheckin
+        testConnectionOnCheckout
+        unreturnedConnectionTimeout
+        user
+        usesTraditionalReflectiveProxies
+        */
+    }
 
 
     protected void tearDown() throws Exception {
index 74e5f5b..f73a4ce 100644 (file)
@@ -28,8 +28,8 @@ public class TwoDataSources extends DefaultTestCase {
     }
     
     public void testTwoDataSources() throws Exception {
-        DataSourceProxy d1 = this.createDefaultDataSource();
-        DataSourceProxy d2 = this.createDefaultDataSource();
+        org.apache.tomcat.jdbc.pool.DataSource d1 = this.createDefaultDataSource();
+        org.apache.tomcat.jdbc.pool.DataSource d2 = this.createDefaultDataSource();
         d1.setRemoveAbandoned(true);
         d1.setRemoveAbandonedTimeout(10);
         d1.setTimeBetweenEvictionRunsMillis(1000);