Hikari 连接池 postgres
Hikari connection pool postgres
我在 spring 引导应用程序中使用 Hikari Cp。
这是我的 java 配置文件:-
private DataSource buildDataSource(String objectValue) {
HikariDataSource dataSource = new HikariDataSource();
JSONObject obj = new JSONObject(objectValue);
dataSource.setInitializationFailTimeout(0);
dataSource.setMaximumPoolSize(5);
dataSource.setIdleTimeout(10000);
dataSource.setMaxLifetime(45000);
dataSource.setDataSourceClassName(obj.getString("dataSourceClassName"));
dataSource.addDataSourceProperty("url", obj.getString("url"));
dataSource.addDataSourceProperty("user", obj.getString("user"));
dataSource.addDataSourceProperty("password", obj.getString("password"));
return dataSource;
}
当我启动应用程序并发送第一个请求后,我得到以下日志。
Added connection org.postgresql.jdbc.PgConnection@66c15b95
2021-07-30 12:00:02.788 INFO 17844 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-07-30 12:00:02.897 DEBUG 17844 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Pool stats (total=1, active=0, idle=1, waiting=0)
几秒钟后,它立即将接下来的四个连接添加到空闲状态:-
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
After adding stats (total=5, active=0, idle=5, waiting=0)
我的问题在这里,我只发送了一个请求,为什么 hikira 又添加了 4 个额外的连接
并且已经有一个空闲连接,为什么它不能重用相同的连接。
并且我已经为每个连接给出了 maxLiftTime
条件,并且在 maxLiftTime 过去后连接仍然处于空闲状态。
所以任何建议都会有所帮助..
minimumIdle: This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. If the idle connections dip below this value and total connections in the pool are less than maximumPoolSize, HikariCP will make a best effort to add additional connections quickly and efficiently. However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize
它正在使用您指定的最大池大小作为最小空闲连接。如果您根本不想要任何空闲连接,请将此值设置为 0
我在 spring 引导应用程序中使用 Hikari Cp。
这是我的 java 配置文件:-
private DataSource buildDataSource(String objectValue) {
HikariDataSource dataSource = new HikariDataSource();
JSONObject obj = new JSONObject(objectValue);
dataSource.setInitializationFailTimeout(0);
dataSource.setMaximumPoolSize(5);
dataSource.setIdleTimeout(10000);
dataSource.setMaxLifetime(45000);
dataSource.setDataSourceClassName(obj.getString("dataSourceClassName"));
dataSource.addDataSourceProperty("url", obj.getString("url"));
dataSource.addDataSourceProperty("user", obj.getString("user"));
dataSource.addDataSourceProperty("password", obj.getString("password"));
return dataSource;
}
当我启动应用程序并发送第一个请求后,我得到以下日志。
Added connection org.postgresql.jdbc.PgConnection@66c15b95
2021-07-30 12:00:02.788 INFO 17844 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-07-30 12:00:02.897 DEBUG 17844 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Pool stats (total=1, active=0, idle=1, waiting=0)
几秒钟后,它立即将接下来的四个连接添加到空闲状态:-
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
Added connection org.postgresql.jdbc.PgConnection@6b9dc322
After adding stats (total=5, active=0, idle=5, waiting=0)
我的问题在这里,我只发送了一个请求,为什么 hikira 又添加了 4 个额外的连接 并且已经有一个空闲连接,为什么它不能重用相同的连接。
并且我已经为每个连接给出了 maxLiftTime
条件,并且在 maxLiftTime 过去后连接仍然处于空闲状态。
所以任何建议都会有所帮助..
minimumIdle: This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. If the idle connections dip below this value and total connections in the pool are less than maximumPoolSize, HikariCP will make a best effort to add additional connections quickly and efficiently. However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize
它正在使用您指定的最大池大小作为最小空闲连接。如果您根本不想要任何空闲连接,请将此值设置为 0