Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

I'm getting the Too many connections issue in multi-tenant DB  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im getting the Too many connections issue in multi-tenant DB, when im hitting to one request it is wotking fine with any number of times,
but when im connecting from client side and sending multiple requests at a time am getting too many connections issue.

Thanks in advance

Caused by: java.sql.SQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
at com.enterprise.portal.configurations.SchemaPerTenantConnectionProvider.getConnection(SchemaPerTenantConnectionProvider.java:74)
at org.hibernate.internal.ContextualJdbcConnectionAccess.obtainConnection(ContextualJdbcConnectionAccess.java:43)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)
... 68 common frames omitted

Here is my sample code.


 
Bartender
Posts: 20346
111
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I normally just configure all that stuff in the applicationContext.xml and skip the java code.

There are 2 likely causes.

1. You've got so many concurrent users that the pool is being exhausted. You need to enlarge the pool and possibly the number of connection channels available on both client and database server machines.

2. OR you're not releasing connections fast enough, and that includes possibly leaking them. If you're using Spring Data properly, you shouldn't be leaking connections - that's one of the reasons why I use Spring Data, in fact. But if your transactions are taking a long time to run, then even without leakage, you can run out. In which case, first consider whether you can optimize the code running while in a transaction and if at all possible move the long-running code outside of the transaction environment. If that doesn't work, see item #1, above.
 
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could be wrong here, but that error looks like it is coming from the database, so it would be the database running out of available connections and not the connection pool.
So there's a mismatch between the pool setup and the database, such that the pool is being allowed to create more connections than the database is configured to handle.
 
Tim Holloway
Bartender
Posts: 20346
111
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Could be wrong here, but that error looks like it is coming from the database, so it would be the database running out of available connections and not the connection pool.
So there's a mismatch between the pool setup and the database, such that the pool is being allowed to create more connections than the database is configured to handle.



That's a definite possibility. Normally, the process of installing a DBMS server involved bumping up certain performance parameters on the DBMS server host machine, including max allowable connections, but it's a good idea to check.

You can run out of server connections if you have a very busy database server, but if all the connections are coming from one client machine, that can indicate that the client application(s) are not efficiently releasing connections. And therefore not only would you be abusing the database server, you'd also be having an overly-large client connection pool.
 
Goodbye moon men. Hello tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!