java - HikariDataSource.getConnection() 在低流量时缓慢,在大流量时快速

标签 java spring oracle pool hikaricp

嗨,我有一个奇怪的问题, 我使用 Oracle db 并拥有带有简单端点的 miroservice,该端点只有 getById,速度极快 3-15 毫秒,但整个操作花费了 250 毫秒。 我深入研究我们的性能监控工具,发现我们在 com.zaxxer.hikari.HikariDataSource.getConnection() 上花费了超过 200 毫秒。

然后我向该端点执行 2000 个请求,持续 10 分钟,时间下降到 1.3ms 。会发生什么?当每小时有 5 个请求时,需要 200 秒才能建立连接, 但是什么时候每秒有4个1.3.?

是否配置错误

spring:
 datasource:
    connectionTimeout: 10000
    maxLifetime: 18000000
    maximumPoolSize: 5
    cachePrepStmts: true
    prepStmtCacheSize: 250
    prepStmtCacheSqlLimit: 2048
    useServerPrepStmts: true

编辑: 据我所知,如果我们有很长一段时间没有调用数据库,那么从 Hikari 包装的物理数据库连接就会关闭。 我需要设置 minimumIdleidleTimeout 吗?如果我有 2 小时不活动,所有连接都会超过 maxLifetime,并且会创建新连接吗?不需要minimumIdle,对吗? 示例: 让有

minimumIdle 1
idleTimeout 2 minutes
maxLifeTime 20 minutes

当我的应用程序在夜间没有人发出请求时,我希望 Hikari 在连接的最后一个请求后 2 分钟关闭每个连接,在最后一个连接关闭后创建一个新连接(并将其保存在池中),并且然后每 20 分钟关闭并重新创建此空闲连接。我理解正确吗?这是我的问题的解决方案吗?

The pool "refill" occurs every 30 seconds or so. So, if there are 5 idle connections and a request comes in and consumes one of them, leaving 4 idle, if the request completes and the connection is returned before the "refill", the pool will again have 5 idle connections and will not grow.

链接: [Understanding HikariCP’s Connection Pooling behaviour] enter image description here

最佳答案

您可以设置idleTimeout当minimumIdle被定义为小于maximumPoolSize时

⌚idleTimeout 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. Idle connections will not be retired once the pool reaches minimumIdle connections.

关于java - HikariDataSource.getConnection() 在低流量时缓慢,在大流量时快速,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58289193/

相关文章:

java - 涉及文档上传和签名的应用程序

java - 使用 VM 选项覆盖 Spring 属性

java - Spring 集成 - 更少的样板?

Java DatabaseMetaData.getColumns() 方法并不适用于所有用户

php - 通知: Array to string conversion in "path of php file" on line 64

java - Selenium webdriver 点击谷歌搜索

java - 如何访问 Bamboo 项目和全局变量

java - 以编程方式增加 UDP 缓冲区 - 这有意义吗?

javascript - 如何在 spring boot 中将映射从本地存储传递到 Controller ?

java - Iseries JAVA 程序 - 连接问题