Reputation: 1124
Does HikariCP supports command timeout in Spring Boot application similar to C#? I am using HikariCP in my Spring boot application. I have enabled connectionTimeout using the following configuration
spring.datasource.hikari.connectionTimeout: 30000
If I increase the number of concurrent users, I get the following exception in logs
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection;
nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
I am perfectly fine with the above exception. I can increase the number of connections. My concern is, there are few endpoints which are taking more than 2 minutes to respond. Those endpoints got DB Connection from pool, but took more time to process. Is there a setting in which I can mention some timeout, so that if DB takes more than some time (Operation time -Say 40 seconds) then it should send SQL exception? Similar to command timeout in C#.
Application.properties
# A list of all Hikari parameters with a good explanation is available on https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby
# This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. Default: same as maximumPoolSize
spring.datasource.hikari.minimumIdle: 10
# This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend.
# Default: 10
spring.datasource.hikari.maximumPoolSize: 20
#This property controls the maximum number of milliseconds that a client (that's you) will wait for a connection from the pool. If this time is exceeded without a connection becoming available, a SQLException will be thrown.
#Lowest acceptable connection timeout is 250 ms. Default: 30000 (30 seconds)
spring.datasource.hikari.connectionTimeout: 30000
# This property controls the maximum amount of time that a connection is allowed to sit idle in the pool. This setting only applies when minimumIdle is defined to be less than maximumPoolSize
# Default: 600000 (10 minutes)
spring.datasource.hikari.idleTimeout: 600000
# This property controls the maximum lifetime of a connection in the pool. An in-use connection will never be retired, only when it is closed will it then be removed.
# Default: 1800000 (30 minutes)
spring.datasource.hikari.maxLifetime: 1800000
# This property sets a SQL statement that will be executed after every new connection creation before adding it to the pool. Default: none
spring.datasource.hikari.connectionInitSql: SELECT 1 FROM DUAL
Upvotes: 1
Views: 10275
Reputation: 9
Druid connection pool have this setting that allows you to set up the timeout:
spring.datasource.druid.query-timeout=10000
Upvotes: -1
Reputation: 12822
As explained in this comment, seems that connectionTimeout
value is used for acquire connection timeout.
You can try setting that to a higher value than 30 secs and see if that helps.
Upvotes: 0