-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: "Too many connections" with Hibernate Connection P
PostPosted: Sun Mar 26, 2006 3:24 pm 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
We are using hibernate 3.0, mysql 5 and JBoss 4.0.2. We are using the datasouce that comes from JBoss and a hibernate config file has the following properties:

Code:
   <property name="hibernate.connection.datasource">java:/dropDS</property>
   <property name="show_sql">false</property>
   <property name="hibernate.hbm2ddl.auto">update</property>
   <property name="hibernate.cglib.use_reflection_optimizer">false</property>
   <property name="hibernate.connection.release_mode">auto</property>
   <property name="hibernate.c3p0.min_size">5</property>
   <property name="hibernate.c3p0.max_size">50</property>
   <property name="hibernate.c3p0.timeout">300</property>
   <property name="hibernate.c3p0.max_statements">50</property>
   <property name="hibernate.c3p0.idle_test_period">3000</property>


Under nice light load, less than 20 concurrent users, all is well. But under a little more load, like 100 concurrent users, we start to see:

Code:
org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (java.sql.SQLException: Data source rejected establishment of connection,  message from server: "Too many connections");


We are running a Dual 64 bit XEON server with 2GB Ram. MySQL 5.0 default connections were left at installation defaults - which I believe is 100 connections.

My question is if we are using the Hibernate connection pool facility, how come we are getting "too many connections" problems?

We have gone over our code and looked at everyplace we get a hibernate session and ensure that we close it in a finally block. In addition, we have made sure that no place in our code do we call a session.connection() call.

Also, for an example of one of the places where we see the exception, is not necessarily when we get a new session. Sometimes, we get that same error when we do something like a criteria.list() call.

Ideas? Suggestions?

Thanks in advance,
Mark


Top
 Profile  
 
 Post subject: Here is a full stack
PostPosted: Sun Mar 26, 2006 3:56 pm 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
Here is one of many full stacks in case you need it.

Code:
13:54:44,468 WARN  [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Data source rejected establishment of connection,  message from server: "Too many connections")
   at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:164)
   at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:519)
   at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:208)
   at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:529)
   at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:410)
   at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:342)
   at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:462)
   at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:894)
   at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:73)
   at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
   at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:304)
   at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:109)
   at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2729)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:809)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:749)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:742)


Top
 Profile  
 
 Post subject: More information
PostPosted: Mon Mar 27, 2006 11:23 am 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
I discovered the main issue with the "Too many connections" exception was that if JBoss crashes or is terminated without the 'shutdown' command, all of the connections being managed will remain open. So if you have 50 available connections on mysql and have 50 as your max connection limit in hibernate or JBoss, then next time around there will not be any connections available.

However, even knowing that and manually deleting the connections in mysql is a side affect of the real problem. It looks like Hibernate is not able to get at the connections once they have been used once. In otherwords, if you have 100 requests and 50 connections, the first 50 will succeed, but the next 50 will timeout waiting for the connection.

Again, I am positive we close every session after its use so I am at a loss why we are unable to reuse the connections once they are used once.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.