1

Does HikariCP supports command timeout in Spring Boot application similar to C#

I am using Hikari Connection Pool 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'm getting 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 find with the above exception. I can increase the number of connections. But my concern is, there are few endpoints which are taking more than 2 minutest to respond. Those endpoints got DB Connection from pool but took more time to process. Is there a setting in which I can mentioned 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
Thiagarajan Ramanathan
  • 1,035
  • 5
  • 24
  • 32

2 Answers2

0

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.

LMC
  • 10,453
  • 2
  • 27
  • 52
0

Druid connection pool have this setting that allows you to set up the timeout:

spring.datasource.druid.query-timeout=10000
danidemi
  • 4,404
  • 4
  • 34
  • 40
tz Yo
  • 11
  • 3
  • connection timeout and query timeout are two different things right.. correct me if I am wrong but the spring.datasource.hikari.connectionTimeout this parameter means spring will wait till the timeout mentioned before throwing exception if db connection is not available – Stunner Jan 22 '21 at 06:43