Hikari连接Timeout Scala SBT 2.11

时间:2017-03-28 03:54:06

标签: scala exception timeout

我有点麻烦让我疯狂..反正。我们以前在heroku上有一个scala app 2.11,java sdk 1.8和postgresql运行顺利..但是我们有点不得不转向azure,因为它们不像java,节点和其他人那样容易支持scala所以我们不得不忍受使用Linux运行应用程序的VM。 postgresql数据库位于另一个支持Azure的linux vm上;

问题是:我们不断收到此错误。

! @73fcml3mf - Internal server error, for (POST) [/signIn] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 37892ms.]]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
        at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
        at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
        at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
        at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98)
        at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
        at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
        at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346)
        at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 37892ms.
        at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:548)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:83)
        at org.jdbcdslog.DataSourceProxyBase.getConnection(DataSourceProxyBase.java:45)
        at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
        at play.api.db.DefaultDatabase.withConnection(Databases.scala:152)
        at play.api.db.DefaultDatabase.withConnection(Databases.scala:148)
        at dal.UserRepository.findByLoginInfo(UserRepository.scala:31)
        at controllers.SignInController$$anonfun$submit$1$$anonfun$apply$2.apply(SignInController.scala:79)

并且它不仅发生在这个特定的请购单上,而且发生在所有的请购单上。超过我们所拥有的一半请购单的帖子。无论如何它真的让我烦恼.. 在我们的application.conf上,这是我们的hikari配置:

play.evolutions {
  # You can disable evolutions for a specific datasource if necessary
  #default.enabled = false
}

## Database Connection Pool
# https://www.playframework.com/documentation/latest/SettingsJDBC
# ~~~~~
# Play doesn't require a JDBC database to run, but you can easily enable one.
#
# libraryDependencies += jdbc
#
play.db {
  # The combination of these two settings results in "db.default" as the
  # default JDBC pool:
  #config = "db"
  #default = "default"

  # Play uses HikariCP as the default connection pool.  You can override
  # settings by changing the prototype:
  prototype {
    # Sets a fixed JDBC connection pool size of 50
    #hikaricp.minimumIdle = 50
    #hikaricp.maximumPoolSize = 50
  }
}

## JDBC Datasource
# https://www.playframework.com/documentation/latest/JavaDatabase
# https://www.playframework.com/documentation/latest/ScalaDatabase
# ~~~~~
# Once JDBC datasource is set up, you can work with several different
# database options:
#
# Slick (Scala preferred option): https://www.playframework.com/documentation/latest/PlaySlick
# JPA (Java preferred option): https://playframework.com/documentation/latest/JavaJPA
# EBean: https://playframework.com/documentation/latest/JavaEbean
# Anorm: https://www.playframework.com/documentation/latest/ScalaAnorm
#
db {
  # You can declare as many datasources as you want.
  # By convention, the default datasource is named `default`

  # https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
  #default.driver = org.h2.Driver
  #default.url = "jdbc:h2:mem:play"
  #default.username = sa
  #default.password = ""

  default.driver="org.postgresql.Driver"
  default.url="jdbc:postgresql://localhost:5432/cuidarse"
  default.url=${?DATABASE_URL}


  # You can turn on SQL logging for any datasource
  # https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
  default.logSql=true
  default.logStatements=true
}

我很抱歉,如果它看起来有点混乱,但我不得不削减一些链接发布..在网上搜索和发现绝对没有任何东西,我试图将应用程序服务器更改为W10,这个例外显着减少但他们仍然在那里,当我们期待最后的时候抓住我们

我甚至会发布一部分代码进行sql查询..我们开始关闭所有连接,但仍然没有好结果

  def insert(user: User) = DB.withConnection { implicit connection =>
    val ret = SQL("INSERT INTO cs_user(full_name, email, cpf, user_active, mobile_uuid, birthday, phone, access_token, insert_date, modified_date) VALUES({fullName}, {email}, {cpf}, {user_active}, {mobile_uuid}, {birthday}, {phone}, {accessToken}, current_timestamp, current_timestamp)").
      on('fullName -> user.fullName, 'email -> user.email, 'cpf -> user.cpf, 'birthday -> user.birthday, 'phone -> user.phone, 'mobile_uuid -> user.mobileUuid, 'user_active -> user.active, 'accessToken -> user.accessToken).executeInsert(SqlParser.scalar[Long].singleOpt)
    connection.close();
    ret   }

当我查看堆栈跟踪时,我可以看到异常在SQL方法中启动。任何类型的查询,选择,更新,删除..

我也注意到在ubuntu postgre vm上输入ps -aux时我可以看到:

postgres  1668  0.0  0.1 188680  5736 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49711) idle
postgres  1669  0.0  0.1 188572  5544 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49712) idle
postgres  1670  0.0  0.1 188444  4096 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49713) idle
postgres  1671  0.0  0.1 188444  4108 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49714) idle
postgres  1672  0.0  0.1 188444  4108 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49715) idle
postgres  1673  0.0  0.1 188444  4104 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49716) idle
postgres  1674  0.0  0.1 188444  4104 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49717) idle
postgres  1675  0.0  0.1 188444  4100 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49718) idle
postgres  1676  0.0  0.1 188444  4104 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49719) idle
postgres  1677  0.0  0.1 188444  4112 ?        Ss   03:16   0:00 postgres: cuidarse cuidarse-stg MYIP(49720) idle
root      1681  0.0  0.0      0     0 ?        S    03:16   0:00 [kworker/u128:2]
postgres  1832  0.0  0.1 188580  4636 ?        Ss   03:25   0:00 postgres: cuidarse cuidarse-stg MYIP(49738) idle
postgres  1833  0.0  0.1 188444  4108 ?        Ss   03:25   0:00 postgres: cuidarse cuidarse-stg MYIP(49739) idle
postgres  1834  0.0  0.1 188444  4100 ?        Ss   03:25   0:00 postgres: cuidarse cuidarse-stg MYIP(49740) idle
postgres  1835  0.0  0.1 188444  4104 ?        Ss   03:25   0:00 postgres: cuidarse cuidarse-stg MYIP(49741) idle
postgres  1854  0.0  0.1 188448  4112 ?        Ss   03:25   0:00 postgres: cuidarse cuidarse-stg MYIP(49743) idle
postgres  1860  0.0  0.1 188448  4108 ?        Ss   03:26   0:00 postgres: cuidarse cuidarse-stg MYIP(49752) idle
postgres  1861  0.0  0.1 188448  4100 ?        Ss   03:26   0:00 postgres: cuidarse cuidarse-stg MYIP(49753) idle
postgres  1870  0.0  0.1 188448  4108 ?        Ss   03:26   0:00 postgres: cuidarse cuidarse-stg MYIP(49757) idle
postgres  1871  0.0  0.1 188448  4108 ?        Ss   03:26   0:00 postgres: cuidarse cuidarse-stg MYIP(49758) idle
postgres  1877  0.0  0.1 188448  4112 ?        Ss   03:27   0:00 postgres: cuidarse cuidarse-stg MYIP(49759) idle

我不确定这意味着什么,但我认为与DB打开的空闲连接太多了。我有时会杀死所有这些论点,但没有多大区别。

好吧,我想我已经在这里发布了所有内容..并且真的希望有人可以帮助我..请:D

对不起我糟糕的英语...如果我不清楚某事请告诉我..晚安,谢谢已经

0 个答案:

没有答案