当前位置: 首页 > 知识库问答 >
问题:

限制jdbc连接池固定量

朱炜
2023-03-14

嗨,我使用micronaut数据和各种jdbc连接池。我第一次有hikari,也尝试了tomcat的一个。

我假设将数据源设置为最大池大小:10 会导致最多 10 个打开连接。但似乎有很多开场和闭幕正在进行。再加上同时处理大量请求,它使用的不仅仅是 10 个连接。问题是,Azure postgresql 总共只允许 100 个连接。

目前我有7个应用程序在访问这个数据库。我希望最多能有70个连接。但实际上要多得多。

我也尝试使用tomcat jdbc池,他的行为有点不同。但也使用超过10个连接。我还使用 java 分析器进行了检查,发现有时每秒多达 100 个打开/关闭连接事件。

除了使用第二个数据库之外,在这种情况下如何行动的任何建议。我希望这个池可以缓冲这些调用,尤其是因为它们来自Kafka的主题。但是,似乎有所不同。

---编辑添加光日志

这是光的日志输出

2020-12-11 11:59:40,983 [main] DEBUG com.zaxxer.hikari.HikariConfig - Driver class org.postgresql.Driver found in Thread context class loader jdk.internal.loader.ClassLoaders$AppClassLoader@2c13da15
2020-12-11 11:59:40,993 [main] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
2020-12-11 11:59:40,999 [main] DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
2020-12-11 11:59:41,000 [main] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
2020-12-11 11:59:41,000 [main] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
2020-12-11 11:59:41,001 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
2020-12-11 11:59:41,001 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery............."SELECT 1;"
2020-12-11 11:59:41,001 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
2020-12-11 11:59:41,002 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
2020-12-11 11:59:41,002 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
2020-12-11 11:59:41,002 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
2020-12-11 11:59:41,003 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
2020-12-11 11:59:41,004 [main] DEBUG com.zaxxer.hikari.HikariConfig - driverClassName................."org.postgresql.Driver"
2020-12-11 11:59:41,004 [main] DEBUG com.zaxxer.hikari.HikariConfig - exceptionOverrideClassName......none
2020-12-11 11:59:41,004 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
2020-12-11 11:59:41,005 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
2020-12-11 11:59:41,005 [main] DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
2020-12-11 11:59:41,005 [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
2020-12-11 11:59:41,006 [main] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
2020-12-11 11:59:41,007 [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:postgresql://URL:5432/postgres
2020-12-11 11:59:41,007 [main] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
2020-12-11 11:59:41,007 [main] DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
2020-12-11 11:59:41,008 [main] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
2020-12-11 11:59:41,008 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
2020-12-11 11:59:41,008 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
2020-12-11 11:59:41,009 [main] DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
2020-12-11 11:59:41,009 [main] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
2020-12-11 11:59:41,009 [main] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
2020-12-11 11:59:41,010 [main] DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
2020-12-11 11:59:41,010 [main] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - schema.........................."SCHEMA"
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
2020-12-11 11:59:41,012 [main] DEBUG com.zaxxer.hikari.HikariConfig - username........................"USERNAME"
2020-12-11 11:59:41,012 [main] DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000

共有1个答案

佘茂才
2023-03-14

我找到了错误——或者至少找到了解决问题的方法。

在将一些数据保存到数据库中的同时,我还尝试更新缓存。但是由于咖啡因加载缓存的变化,每次保存也会导致对完全相同的数据对象实例进行获取。

我的猜测是由于造成麻烦的交易。将 cache.get 替换为 cache.replace 后,一切正常。

 类似资料:
  • 我在karaf中的pax-jdbc的池连接有问题,我试图通过blueprint.xml注入一个MySQL数据源(DS)到我的项目中,为了测试它,我已经建立了一个karaf命令,将DS注入karaf命令类并使用该连接执行查询。这是可以的,但是问题是当我执行命令很多次时,每次执行都会创建一个新的DS实例,并且池连接无法打开到MySQL的新连接,因为池已经达到极限。 我已通过以下链接将代码上传到gith

  • 问题陈述 我们在嵌入式模式下使用H2已有一段时间了。它上面配置了一个连接池。以下是当前池配置: H2配置: *跳过用户名和密码属性。 我们已经通过记录池属性验证了上述配置的有效性。 这个设置的问题是,我们观察到连接池经常(尽管是间歇性的)耗尽,一旦连接池达到最大限制,它就开始为一些查询抛出以下异常。 SqlExceptionHelper.log异常(SqlExceptionHelper.java:

  • 前几天我经历了应用程序的中断,我需要了解以后如何避免这种情况。 我们有一个运行在Tomcat7上的基于Java的web应用程序。应用程序连接到几个不同的数据源,包括Oracle数据库。 下面是我对连接验证的理解。 连接在空闲时(testWhileIdle=false)、借用时(testOnBorrow=false)、返回时(testOnReturn=false) 由于timeBetweenEvic

  • 我使用作为我的数据源实现,我的代码获取连接并关闭连接,如下所示: 当我完成连接工作时,我将关闭它 我的问题是:确实是关闭的,所以当连接像一样关闭时,数据源是如何工作的。我听说datasource connection close并不是真正的close,只是release,但我在datasource类中找不到release API。我想知道datasource如何管理数据库连接的创建、关闭和释放。

  • 我们有一个spring-boot应用程序,它使用嵌入式tomcat进行部署,并使用MySQL后端的默认tomcat-jdbc连接池,而没有为MySQL或tomcat端定制。 该应用程序有一些调度程序,它们主要在一天中的特定时间运行,即在昨天的最后一次cron运行和今天的第一次cron运行之间,有超过9个小时的间隙。然而,无论何时cron在早期运行,它都从未遇到过空闲连接问题。 现在我们看到一条错误

  • 我们刚刚从dbcp迁移到tomcat jdbc连池。我们在加载中尝试了系统,收到了以下异常: 请注意: 不忙的连接在哪里?忙的数字在这之后一直在下降,但我们仍然没有得到任何连接。 有什么想法吗? 配置: env:ubuntu和tomcat 6. db-mysql