Saturday, March 3, 2012

Re: Connection Pool

I have been using the commons dbcp pool successfully (with straight JDBC, no JDO/JPA).  It has a facility for testing a connection before returning from pool, which prevents any errors if the db instance 'went to sleep'.  The test query adds 10-15ms seconds before every query, which is acceptable to me.  DBCP has more efficient ways to check for dead connections (e.g. every x seconds while sitting in pool) but these can't be used because they involve starting up new maintenance threads, which aren't allowed in AppEngine.   

Of course, this will prevent any errors, but it won't keep some requests from taking upwards of 15 seconds while they wait for the db instance to come up.  I deal with that by having my monitoring server hit a url every 5 minutes that involves a db call, so even in periods of very low activity the db should stay on.

See more here:

http://commons.apache.org/dbcp/configuration.html

Here's how I wire up my datasource and transaction manager in Spring:

    <bean id="dsSearchIndex" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
        <property name="url" value="jdbc:google:rdbms://xxxx.com:web-prod:searchindex/ctssearchidx"/>
        <property name="username" value="xxx"/>
        <property name="password" value="xxx"/>
        <property name="testOnBorrow" value="true"/>
        <property name="validationQuery" value="select 1"/>
    </bean>
<bean id="tmSearchIndex" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dsSearchIndex"/>
   <qualifier value="searchIndex"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="tmSearchIndex" />
    <bean id="daoSearchIndex" class="com.commentous.searchindex.SearchIndexJdbcDao">
        <property name="dataSource" ref="dsSearchIndex"/>
    </bean>





On Tuesday, November 1, 2011 11:44:30 AM UTC-7, javabuddy wrote:
How to establish Connection Pool in GAE using AppEngineDriver in Cloud
SQL or native datastore??

Thanks

No comments:

Post a Comment