Hi,
I've been experimenting a little with connection pools performance
and it seems the C3P0 connection pool (http://sourceforge.net/projects/c3p0/)
is designed for slightly better scalability than the DBCP one we're
using today.

In particular in a WMS request benchmark, and when reaching the high
number of clients (40 threads against a pool of 20 connections) the pool
provides a 5-10% speed increase over a, which is not so bad given it's
just a library change.

I would like to add it to the mix, just not sure how.
Shall we replace DBCP? Or give people another option, a list of
supported pools that does include DBCP and C3P0?

The current connection options are pretty much supported by both
pools, thought C3P0 has more configuration knobs to offer. For
example, the connection validation can happen in a background thread
as opposed to doing every time a connection is extracted from
the pool.

If anybody wants to try it out against PostGIS I've attached a quick
test for the NG datastore to this mail (non definitive, the
real thing should be probably moved to the core JDBC module so that
every JDBC datastore is affected).

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.
Index: src/main/java/org/geotools/data/postgis/PostgisNGDataStoreFactory.java
===================================================================
--- src/main/java/org/geotools/data/postgis/PostgisNGDataStoreFactory.java	(revisione 33641)
+++ src/main/java/org/geotools/data/postgis/PostgisNGDataStoreFactory.java	(copia locale)
@@ -16,13 +16,23 @@
  */
 package org.geotools.data.postgis;
 
+import java.beans.PropertyVetoException;
 import java.io.IOException;
+import java.sql.SQLException;
 import java.util.Map;
 
+import javax.sql.DataSource;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.geotools.data.jdbc.datasource.AbstractManageableDataSource;
+import org.geotools.data.jdbc.datasource.DBCPDataSource;
 import org.geotools.jdbc.JDBCDataStore;
 import org.geotools.jdbc.JDBCDataStoreFactory;
+import org.geotools.jdbc.PreparedStatementSQLDialect;
 import org.geotools.jdbc.SQLDialect;
 
+import com.mchange.v2.c3p0.ComboPooledDataSource;
+
 public class PostgisNGDataStoreFactory extends JDBCDataStoreFactory {
     /** parameter for namespace of the datastore */
     public static final Param LOOSEBBOX = new Param("Loose bbox", Boolean.class, "Perform only primary filter on bbox", false, Boolean.TRUE);
@@ -100,5 +110,79 @@
         int port = (Integer) PORT.lookUp(params);
         return "jdbc:postgresql" + "://" + host + ":" + port + "/" + db;
     }
+    
+    
+    protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException {
+        ComboPooledDataSource dataSource = new ComboPooledDataSource();
+        dataSource.setMaxStatements(dialect instanceof PreparedStatementSQLDialect ? 50 : 0);
 
+        // driver
+        try {
+            dataSource.setDriverClass(getDriverClassName());
+        } catch(PropertyVetoException e) {
+            throw new IOException("Could not set the driver class name");
+        }
+
+        // url
+        dataSource.setJdbcUrl(getJDBCUrl(params));
+
+        // username
+        String user = (String) USER.lookUp(params);
+        dataSource.setUser(user);
+
+        // password
+        String passwd = (String) PASSWD.lookUp(params);
+        if (passwd != null) {
+            dataSource.setPassword(passwd);
+        }
+        
+        // max wait
+        Integer maxWait = (Integer) MAXWAIT.lookUp(params);
+        if (maxWait != null && maxWait != -1) {
+            dataSource.setCheckoutTimeout(maxWait * 1000);
+        }
+        
+        // connection pooling options
+        Integer minConn = (Integer) MINCONN.lookUp(params);
+        if ( minConn != null ) {
+            dataSource.setMinPoolSize(minConn);    
+        }
+        
+        Integer maxConn = (Integer) MAXCONN.lookUp(params);
+        if ( maxConn != null ) {
+            dataSource.setMaxPoolSize(maxConn);
+        }
+        
+        Boolean validate = (Boolean) VALIDATECONN.lookUp(params);
+        if(validate != null && validate && getValidationQuery() != null) {
+            dataSource.setTestConnectionOnCheckout(true);
+            dataSource.setPreferredTestQuery(getValidationQuery());
+        }
+        
+        return new C3P0DataSource(dataSource);
+    }
+    
+    public class C3P0DataSource extends AbstractManageableDataSource {
+
+        public C3P0DataSource(ComboPooledDataSource wrapped) {
+            super(wrapped);
+
+        }
+
+        public void close() throws SQLException {
+            ((ComboPooledDataSource) wrapped).close();
+        }
+
+        public boolean isWrapperFor(Class type) throws SQLException {
+            return false;
+            //return this.wrapped.isWrapperFor(type);
+        }
+
+        public Object unwrap(Class type) throws SQLException {
+            return null;
+            //return this.wrapped.unwrap(type);
+        }
+
+    }
+
 }
Index: pom.xml
===================================================================
--- pom.xml	(revisione 33641)
+++ pom.xml	(copia locale)
@@ -79,6 +79,11 @@
       <groupId>postgresql</groupId>
       <artifactId>postgresql</artifactId>
     </dependency>
+    <dependency>
+	  <groupId>c3p0</groupId>
+	  <artifactId>c3p0</artifactId>
+	  <version>0.9.1.2</version>
+    </dependency>
   </dependencies>
 
 </project>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to