简体   繁体   中英

Java Connection is not available, request timed out after 30000ms

what's this?

o.h.e.jdbc.spi.SqlExceptionHelper:  chatbotPrechatDS - Connection is not available, request timed out after 30000ms.

I got an application java 8 deployed in aws elastic beanstalk, we are two servers to host this application, and a RDS mysql.

Hikari version:

<hikaricp.version>4.0.3</hikaricp.version>

config:

  connection-timeout: 600000
  maximum-pool-size: 500
  max-lifetime: 1800000
  minimum-idle: 20
  validation-timeout: 3000
  idle-timeout: 60000

Could this error be related to high memory consumption?

"Connection not available" errors in my experience are about the connection pool using up all its slots. It has nothing to do with not being able to connect to the database server. The db server is probably happy to take more connections (up to max_connections ), but the Java client's connection pool is too small.

That said, you seem to have a connection pool size of 500 which should be enough for practically any app. The idea of a connection pool is that a small number of connections can be shared among a much greater number of client threads.

Where this runs into trouble is when a client thread holds onto a connection too long.

This could be a code design issue. You're supposed to release the connection back to the connection pool when you're done using it, even if the thread is not done running other code.

Another possible problem is that the thread is still executing SQL queries because they are poorly optimized. So it can't finish using the db connection fast enough to handle increased rate of requests to the app, and soon all the connections in the pool become occupied. The solution to this is to optimize your queries, one by one, starting either with those that are taking too long or those that are run most frequently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM