Slick / HikariCP / MySQL总是超时

时间:2018-07-05 21:45:08

标签: scala jdbc playframework slick hikaricp

我在Slick上使用Play(2.6),我的数据库连接每隔第二或第三次尝试就会超时。重新建立连接的唯一方法是使用sbt run重新启动应用程序。这让我发疯,任何帮助都令人感激。

要清楚,我正在将Slick与本地MySQL数据库一起使用,以实现非常轻量级的使用。

build.sbt

libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.11"
libraryDependencies += "com.typesafe.slick" %% "slick" % "3.2.3"
libraryDependencies += "com.typesafe.slick" %% "slick-hikaricp" % "3.2.3"

application.conf

# db connections = ((physical_core_count * 2) + effective_spindle_count)
fixedConnectionPool = 5

repository.dispatcher {
  executor = "thread-pool-executor"
  throughput = 1
  thread-pool-executor {
    fixed-pool-size = ${fixedConnectionPool}
  }
}

错误消息:

java.sql.SQLTransientConnectionException: <dbconfig> - Connection is not available, request timed out after 1001ms.

堆栈跟踪:

com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:548)
com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)
com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:83)
slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:14)
slick.jdbc.JdbcBackend$BaseSession.<init>(JdbcBackend.scala:453)
slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:46)
slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:37)
slick.basic.BasicBackend$DatabaseDef.acquireSession(BasicBackend.scala:249)
slick.basic.BasicBackend$DatabaseDef.acquireSession$(BasicBackend.scala:248)
slick.jdbc.JdbcBackend$DatabaseDef.acquireSession(JdbcBackend.scala:37)
slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:274)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)

更新

我没有在application.conf中包含特定的数据库配置:

<name> {
  slick.driver = scala.slick.driver.MySQLDriver
  driver = "com.mysql.cj.jdbc.Driver"
  url = __
  user = __
  password = __
}

我已添加到配置中:

  keepAliveConnection = true
  connectionPool = disabled

它工作正常。

0 个答案:

没有答案