ActiveMQ Starved DB Connections

This is indicated by the following error:

2011-12-18 01:25:29,132 [erSimpleAppMain] WARN JDBCPersistenceAdapter - Could not get JDBC connection: Network error IOException: Connection refused: connect
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:410)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at net.sourceforge.jtds.jdbcx.JtdsDataSource.getConnection(JtdsDataSource.java:188)
at net.sourceforge.jtds.jdbcx.JtdsDataSource.getConnection(JtdsDataSource.java:137)
at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:58)
at org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter.doGetLastMessageStoreSequenceId(DefaultJDBCAdapter.java:159)
at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.getLastMessageBrokerSequenceId(JDBCPersistenceAdapter.java:230)
at org.apache.activemq.broker.region.DestinationFactoryImpl.getLastMessageBrokerSequenceId(DestinationFactoryImpl.java:145)
at org.apache.activemq.broker.region.RegionBroker.(RegionBroker.java:122)
at org.apache.activemq.broker.jmx.ManagedRegionBroker.(ManagedRegionBroker.java:99)
at org.apache.activemq.broker.BrokerService.createRegionBroker(BrokerService.java:1830)
at org.apache.activemq.broker.BrokerService.createRegionBroker(BrokerService.java:1824)
at org.apache.activemq.broker.BrokerService.createBroker(BrokerService.java:1781)
at org.apache.activemq.broker.BrokerService.getBroker(BrokerService.java:766)
at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.start(JDBCPersistenceAdapter.java:296)
at org.apache.activemq.broker.BrokerService.start(BrokerService.java:493)
at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)

The solution is found here:

http://activemq.apache.org/sqlserver.html

Ideally this would be solved by using database connection pooling, but I have yet to find a good way to do that.

A note about the jTDS Drivers: Using both the JtdsDataSource and the DBCP BasicDataSource seem to result in client connection starvation on Windows. The JtdsDataSource is better behaved, though, i.e. it doesn’t throw an exception. There is mileage in upping the maximum number of client ports and dropping the Tcp wait delay down to 30 seconds. Use RegEdit to add the following values:

Name Type Key Value Description
TcpTimedWaitDelay DWORD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\TCPIP\Parameters 30 (Decimal) Reduces the time a connection spends in TIME_WAIT to 30 seconds
MaxUserPort DWORD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\TCPIP\Parameters 32768 (Decimal) Increases the number of ports a client application can use to 32768

 

This entry was posted in Tips, Tricks, and Troubleshooting. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>