You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2009/04/23 18:02:33 UTC

svn commit: r767949 - in /tomcat/trunk/modules/jdbc-pool: .classpath test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java test/org/apache/tomcat/jdbc/test/DefaultTestCase.java test/org/apache/tomcat/jdbc/test/TwoDataSources.java

Author: fhanik
Date: Thu Apr 23 16:02:32 2009
New Revision: 767949

URL: http://svn.apache.org/viewvc?rev=767949&view=rev
Log:
Added in c3p0 to the performance tests, it doesn't even perform as well as DBCP, which is contradictory to what the internet is claiming

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

Modified: tomcat/trunk/modules/jdbc-pool/.classpath
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/.classpath?rev=767949&r1=767948&r2=767949&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/.classpath (original)
+++ tomcat/trunk/modules/jdbc-pool/.classpath Thu Apr 23 16:02:32 2009
@@ -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>

Modified: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java?rev=767949&r1=767948&r2=767949&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java (original)
+++ tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java Thu Apr 23 16:02:32 2009
@@ -23,7 +23,6 @@
 
 import javax.sql.DataSource;
 
-import org.apache.tomcat.jdbc.pool.DataSourceFactory;
 
 /**
  * @author Filip Hanik
@@ -67,7 +66,7 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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 @@
         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;

Modified: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java?rev=767949&r1=767948&r2=767949&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java (original)
+++ tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java Thu Apr 23 16:02:32 2009
@@ -19,6 +19,8 @@
 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 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 @@
             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 {

Modified: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java?rev=767949&r1=767948&r2=767949&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java (original)
+++ tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java Thu Apr 23 16:02:32 2009
@@ -28,8 +28,8 @@
     }
     
     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);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org