HikariCP 是否支持类似于 C# 的 Spring Boot 应用程序中的命令超时

问题描述 投票:0回答:2

HikariCP 是否支持类似于 C# 的 Spring Boot 应用程序中的命令超时

我在 Spring boot 应用程序中使用 Hikari 连接池。我使用以下配置启用了connectionTimeout

spring.datasource.hikari.connectionTimeout: 30000

如果我增加并发用户数,我会在日志中收到以下异常

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.

除了上述例外,我完全可以找到。我可以增加连接数。但我担心的是,很少有端点的响应时间超过 2 分钟。这些端点从池中获取数据库连接,但需要更多时间来处理。是否有一个设置,我可以在其中提到一些超时,以便如果数据库花费超过一段时间(操作时间 - 比如说 40 秒),那么它应该发送 SQL 异常。类似于 C# 中的命令超时

应用程序.属性

# 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
spring spring-boot connection-pooling hikaricp
2个回答
0
投票

正如此评论中所解释的,似乎

connectionTimeout
值用于获取连接超时。 您可以尝试将其设置为高于 30 秒的值,看看是否有帮助。


0
投票

Druid 连接池 有这个设置,允许您设置超时:

spring.datasource.druid.query-timeout=10000
© www.soinside.com 2019 - 2024. All rights reserved.