7 Replies Latest reply on Mar 18, 2013 7:52 AM by paul.h

    Connection pooling in Fuse ESB

    paul.h

      Fuse ESB Enterprise 7.1.0

      PostgreSQL 9.2

       

      I use tomcat jdbc pool with spring JdbcTemplate in my fuse esb applications for work with postgresql database. I publish connection pool as datasource service in osgi environment in blueprint and it is reused by several applications.

      When I started testing the application, I found an interesting bug which concerns all data sources in XA mode.

      I digg in sources of next libraries:

      • org.apache.aries.transaction/org.apache.aries.transaction.jdbc/1.0.1.fuse-71-047

      • org.apache.aries.transaction/org.apache.aries.transaction.manager/1.0.1.fuse-71-047

      • spring-jdbc

      • tomcat jdbc-pool

      and found, that JdbcTemplate don't close connection if it's the transactional, and aries hasn't any option and code to release connection after global transaction commit or rollback.

       

      For example I have next simple bean:

      public class TestBean {

      private JdbcTemplate jdbcTemplate;

       

      public TestBean(JdbcTemplate jdbcTemplate) {

      this.jdbcTemplate = jdbcTemplate;

      }

       

      @Transacted

      public void test1() {

      jdbcTemplate.update(....);

      }

       

      @Transacted

      public void test2() {

      jdbcTemplate.update(...);

      }

       

      @Transacted

      public void test3() {

      jdbcTemplate.update(...);       

      }

      }

       

      I have next situation:

      1) I execute update method on jdbcTemplate in my test1() method. Spring container propagate global transaction context to it and after finishing update not release connection.

      2) I execute next methods test2(), test3(), etc in same global transaction context

      3) Transaction manager execute auto commit after all and also not realese used jdbc connections.

      4) After next N executions getConnection() at tomcat jdbc pool datasource object I catch exception with message:

      Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none availablesize:50; busy:50; idle:0; lastwait:30000

       

      Pool consider that all connections is busy, but actually all 50 connections simply is not released!

      Workaround for tomcat jdbc-pool: removeAbandoned = true, but it is crutches.

       

      Whether there are any instructions on use of the connection pooling in fuse esb except use of ancient dbcp or c3p0 libraries?

       

      Thanks!

        • 1. Re: Connection pooling in Fuse ESB
          paul.h

          up!

          • 2. Re: Connection pooling in Fuse ESB
            davsclaus

            What about Apache Commons Pool. Its used by some of the Camel components also.

            http://commons.apache.org/proper/commons-pool/

             

            And it's OSGi JAR out of the box (eg version 1.6 we use).

            • 3. Re: Connection pooling in Fuse ESB
              davsclaus

              Ah I guess you want a JDBC connection pool API on top of that so you do not need to write any code. And I guess Apache Commons Pool is a generic pool library and don't offer any JDBC API out of the box.

              • 4. Re: Connection pooling in Fuse ESB
                ffang

                Hi,

                 

                Per the comment for org.apache.aries.transaction.jdbc.internal.XADatasourceEnlistingWrapper,

                 

                /**

                 

                • This class allows JDBC XA data sources to participate in global transactions,

                 

                • via the {@link org.apache.aries.transaction.jdbc.internal.ConnectionWrapper} that is returned. The only service provided

                 

                • is enlistment/delistment of the associated {@link XAResource} in transactions.

                 

                • Important consideration such as connection pooling and error handling are

                 

                • completely ignored.

                *

                */

                 

                If I read it correctly, aries transaction JDBC XA data source doesn't support connection pool at all.

                 

                Freeman

                • 5. Re: Connection pooling in Fuse ESB
                  paul.h

                  Hello,

                   

                  I understand this as "connection pooling not work out-of-box" and this is true

                  But I can't understand why aries isn't able to close connection after XA commit. Or is it work of connection pool?

                  • 6. Re: Connection pooling in Fuse ESB
                    ffang

                    Hi,

                    aries XADatasourceEnlistingWrapper won't work with connection pool anyway(as the comment explicitly mentioned it).

                     

                    But it do close the connection after XA commit, the code is

                     

                    public void afterCompletion(int status) {
                                Connection connection = connectionMap.remove(key);
                                if (connection != null) {
                                    try {
                                        connection.close();
                                    } catch (SQLException e) {
                                        // ignore
                                    }
                                }
                            }
                    

                     

                    Not sure what aries transaction version you're using, if you use  aries transaction 1.0.x, you can set break point here in XADatasourceEnlistingWrapper and see it get invoked.

                     

                    Freeman

                    • 7. Re: Connection pooling in Fuse ESB
                      paul.h

                      I have found similar bugs in bugtracker:

                      http://fusesource.com/issues/browse/ENTESB-633

                      http://fusesource.com/issues/browse/ENTESB-610

                      But there is no workaround in comments and these bugs are still not fixed The problem is in Aries itself.