This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9693|Reply: 1

[Source] Spring Boot database connection pool HikariPool optimization

[Copy link]
Posted on 2021-11-25 14:55:15 | | | |
Spring-Boot-2.0.0-M1 version changes the default database connection pool from tomcat jdbc pool to hikari, and when running the spring boot application, the console outputs the following
2021-11-25 14:48:09.429  INFO 22236 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-11-25 14:48:09.813  INFO 22236 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.

The default values for Hikari's default configuration are as follows:
{"connection-timeout":30000,"maximum-pool-size":10,"max-lifetime":1800000,"minimum-idle":10,"validation-timeout":5000,"idle-timeout":600000}

nameConstructor defaultsThe default configuration is the value after validatevalidatereset
minIdle-110minIdle<0 or minIdle>maxPoolSize, it is reset to maxPoolSize
maxPoolSize-110If maxPoolSize is less than 1, it is reset. When minIdle<=0 is reset to DEFAULT_POOL_SIZE, it is 10; If minIdle>0, it resets to the value of minIdle
maxLifetimeMINUTES.toMillis(30) = 18000001800000If it is not equal to 0 and less than 30 seconds, it will be reset back to 30 minutes
connectionTimeoutSECONDS.toMillis(30) = 3000030000If it is less than 250 ms, it is reset back to 30 seconds
validationTimeoutSECONDS.toMillis(5) = 50005000If it is less than 250 ms, it is reset back to 5 seconds
loginTimeout1030Math.max(1, (int) MILLISECONDS.toSeconds(500L + connectionTimeout)), which is the maximum of connectionTimeout+500ms to convert the number of seconds to the whole and 1
idleTimeoutMINUTES.toMillis(10) = 600000600000If idleTimeout+1 second > maxLifetime and maxLifetime >0, it will be reset to 0; If idleTimeout!=0 and less than 10 seconds, it is reset to 10 seconds
leakDetectionThreshold00If it is greater than 0 and not a unit test, it is further judged that (leakDetectionThreshold < SECONDS.toMillis(2) or (leakDetectionThreshold > maxLifetime && maxLifetime > 0), will be reset to 0. That is, if it is to take effect, it must be >0, and it cannot be less than 2 seconds, and when maxLifetime > 0 hours cannot be greater than maxLifetime
initializationFailTimeout11-
isAutoCommittruetrue-
isReadOnlyfalsefasle-
isAllowPoolSuspensionfalsefalse-
isIsolateInternalQueriesfalsefalse-
isRegisterMbeansfalsefalse-
sealedfalsetrueThis flag is true after the run starts, indicating that the modification is no longer running
poolNamenullHikariPool-1-
catalognullnull-
connectionInitSqlnullnull-
connectionTestQuerynullnull-
dataSourceClassNamenullnull-
schemanullnull-
transactionIsolationNamenullnull-
dataSourcenullnull-
dataSourceProperties{}{}-
threadFactorynullnull-
scheduledExecutornullnull-
metricsTrackerFactorynullnull-
metricRegistrynullnull-
healthCheckRegistrynullnull-
healthCheckProperties{}{}-

When performing a stress test, the application may report the following errors:

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.
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
        at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
        at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
        at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337)
        at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
        at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
        at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81)
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
        at com.sun.proxy.$Proxy224.query(Unknown Source)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)
        ... 114 more
Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
        at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:695)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:197)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:162)
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)
        at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116)
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
        ... 126 more


Mistake:Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.

The Controller outputs the HikariDataSource configuration interface code as follows:

Optimize the scheme, increase the maximum number of threads and increase the number of connections held idle, and modify the application.yml configuration as follows:

(End)




Previous:The difference between getLastRowNum() and getLastCellNum() in POIs
Next:Comparison of the testing tools LoadRunner and Jmeter
Posted on 2022-12-14 21:46:53 |
Learn to learn
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com