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}
| name | Constructor defaults | The default configuration is the value after validate | validatereset | | minIdle | -1 | 10 | minIdle<0 or minIdle>maxPoolSize, it is reset to maxPoolSize | | maxPoolSize | -1 | 10 | If 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 | | maxLifetime | MINUTES.toMillis(30) = 1800000 | 1800000 | If it is not equal to 0 and less than 30 seconds, it will be reset back to 30 minutes | | connectionTimeout | SECONDS.toMillis(30) = 30000 | 30000 | If it is less than 250 ms, it is reset back to 30 seconds | | validationTimeout | SECONDS.toMillis(5) = 5000 | 5000 | If it is less than 250 ms, it is reset back to 5 seconds | | loginTimeout | 10 | 30 | Math.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 | | idleTimeout | MINUTES.toMillis(10) = 600000 | 600000 | If 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 | | leakDetectionThreshold | 0 | 0 | If 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 | | initializationFailTimeout | 1 | 1 | - | | isAutoCommit | true | true | - | | isReadOnly | false | fasle | - | | isAllowPoolSuspension | false | false | - | | isIsolateInternalQueries | false | false | - | | isRegisterMbeans | false | false | - | | sealed | false | true | This flag is true after the run starts, indicating that the modification is no longer running | | poolName | null | HikariPool-1 | - | | catalog | null | null | - | | connectionInitSql | null | null | - | | connectionTestQuery | null | null | - | | dataSourceClassName | null | null | - | | schema | null | null | - | | transactionIsolationName | null | null | - | | dataSource | null | null | - | | dataSourceProperties | {} | {} | - | | threadFactory | null | null | - | | scheduledExecutor | null | null | - | | metricsTrackerFactory | null | null | - | | metricRegistry | null | null | - | | healthCheckRegistry | null | null | - | | 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)
|