【问题标题】:Grails Gorm Timeout: Pool empty. Unable to fetch a connectionGrails Gorm 超时:池为空。无法获取连接
【发布时间】:2017-01-13 12:43:02
【问题描述】:

超时:池为空。无法在 10 秒内获取连接,无可用 [size:7;忙:0;空闲:0;最后等待:10000]

我的应用程序上线很长时间后出现上述错误。

以下是我的 GORM 数据库配置:

propertyShortSlave:
    pooled: true
    jmxExport: true
    driverClassName: com.mysql.jdbc.Driver
    url: url
    username: uuuuuu
    password: pppppp
    dbCreate: validate
    readOnly: true
    dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    properties:
            initialSize: 5
            maxActive: 7
            minIdle: 5
            validationQuery: SELECT 1
            maxIdle: 7
            maxWait: 10000
            maxAge: 600000
            timeBetweenEvictionRunsMillis: 5000
            minEvictableIdleTimeMillis: 60000
            validationQueryTimeout: 3
            validationInterval: 15000
            testOnBorrow: true
            testWhileIdle: true
            testOnReturn: false
            jdbcInterceptors: "ConnectionState;StatementCache(max=200)"

我该如何解决?

【问题讨论】:

  • 你试过 reconnect=true 在 url 上吗? url = "jdbc:mysql://localhost:3306/test?autoReconnect=true" 很难说,因为你还没有定义 url....
  • 我试过这个,但没有 validationQuery 属性。在这种情况下,连接很快就会关闭。但我还没有尝试使用validationQuery 自动重新连接
  • github.com/vahidhedayati/kchat/blob/master/grails-app/conf/… 我在生产环境中运行了这个配置,没有问题 validationQuery="SELECT 1" 必须设置它才能保持连接打开。
  • 这意味着我不应该提供 maxActive 和 maxIdle 数。
  • 但是没有这些数字,我们如何控制连接数。它可能会建立很多连接并减慢数据库。

标签: hibernate grails grails-orm


【解决方案1】:

尝试使用这些:

dataSource {
....
 url = "jdbc:mysql://localhost:3306/databaseName?autoReconnect=true&useUnicode=true&CharSet=UTF-8&characterEncoding=UTF-8"
....
properties {
 ....
 validationQuery = "SELECT 1"
 ....
 }
}

【讨论】:

  • 您以 JSON 格式发帖,实际上是 YAML 格式。但这个想法是正确的。
  • 这是 Grails 在 2.x 版本中使用的 groovy 闭包。 YAML 在 Grails 3.x 之后引入
  • 正确,我只是为问题的作者做个笔记,因为不同的格式可能会让新手感到困惑。
  • @Jeeveshpandey,我还没有尝试过这个结果,因为现在我的连接工作正常,但是当问题再次出现时,我会应用这个解决方案。现在我只是增加了 maxActive 的数量与 20 的连接。让我们看看它是如何工作的。
猜你喜欢
  • 2014-02-19
  • 2011-11-08
  • 2014-01-09
  • 1970-01-01
  • 2012-12-08
  • 2012-04-19
  • 2015-03-27
  • 1970-01-01
  • 2017-03-31
相关资源
最近更新 更多