我的 Play Framework 应用程序(托管在 Heroku 上)中有一个 Akka 线程,每 10 分钟调用一次。在这个线程中,我快速连续访问数据库中的许多模型。编译并启动应用程序后,该线程可以正常运行几个小时。最终(并且出于未知的原因)记录器返回以下内容:
c.j.b.PoolWatchThread - Error in trying to obtain a connection
我的数据库配置(Heroku 的 PostgreSQL 基本计划)如下所示:
db.default.user=USER
db.default.password=PASS
db.default.jndiName=DefaultDS
db.default.driver=org.postgresql.Driver
db.default.url=URL
db.default.partitionCount=2
db.default.maxConnectionsPerPartition=5
db.default.minConnectionsPerPartition=5
db.default.acquireIncrement=1
db.default.acquireRetryAttempts=1
db.default.acquireRetryDelay=5 seconds
db.default.maxConnectionAge=1 hour
db.default.idleMaxAge=10 minute
我在没有解决问题的情况下调整了这些变量。
这是堆栈跟踪
2013-08-11T21:53:29.304108+00:00 app[web.2]: [error] c.j.b.PoolWatchThread - Error in trying to obtain a connection. Retrying in 5000ms
2013-08-11T21:53:29.304108+00:00 app[web.2]: org.postgresql.util.PSQLException: FATAL: too many connections for role "[DB USER NAME]"
2013-08-11T21:53:29.304108+00:00 app[web.2]: at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:469) ~[postgresql-9.1-901.jdbc4.jar:na]
2013-08-11T21:53:29.304108+00:00 app[web.2]: at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112) ~[postgresql-9.1-901.jdbc4.jar:na]
2013-08-11T21:53:29.304108+00:00 app[web.2]: at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) ~[postgresql-9.1-901.jdbc4.jar:na]
2013-08-11T21:53:29.304108+00:00 app[web.2]: at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) ~[postgresql-9.1-901.jdbc4.jar:na]
2013-08-11T21:53:29.304108+00:00 app[web.2]: at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) ~[postgresql-9.1-901.jdbc4.jar:na]
2013-08-11T21:53:29.304108+00:00 app[web.2]: at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22) ~[postgresql-9.1-901.jdbc4.jar:na]
我有一种预感,这可能与我在数据库中查询模型的方式和时间有关。像,也许连接没有被释放?帮助表示赞赏。
编辑:
更多来自记录器
2013-08-13T14:43:49.257852+00:00 app[web.1]: javax.persistence.PersistenceException: java.sql.SQLException: Timed out waiting for a free available connection.
2013-08-13T14:43:49.257852+00:00 app[web.1]: at com.avaje.ebeaninternal.server.transaction.TransactionManager.createQueryTransaction(TransactionManager.java:368)
2013-08-13T14:43:49.257852+00:00 app[web.1]: at com.avaje.ebeaninternal.server.core.DefaultServer.createQueryTransaction(DefaultServer.java:2060)
2013-08-13T14:43:49.257852+00:00 app[web.1]: at com.avaje.ebeaninternal.server.core.OrmQueryRequest.initTransIfRequired(OrmQueryRequest.java:181)
2013-08-13T14:43:49.257852+00:00 app[web.1]: at com.avaje.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:1501)
2013-08-13T14:43:49.257852+00:00 app[web.1]: at com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery.findList(DefaultOrmQuery.java:904)
2013-08-13T14:43:49.257852+00:00 app[web.1]: at com.avaje.ebeaninternal.util.DefaultExpressionList.findList(DefaultExpressionList.java:177)
2013-08-13T14:43:49.257852+00:00 app[web.1]: at models.Person.findByHandle(Person.java:85)
2013-08-13T14:43:49.257852+00:00 app[web.1]: at models.NapalmJob.run(NapalmJob.java:41)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at models.NapalmActor.onReceive(NapalmActor.java:9)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:159)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at akka.actor.ActorCell.invoke(ActorCell.scala:386)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at akka.dispatch.Mailbox.run(Mailbox.scala:212)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
2013-08-13T14:43:49.258049+00:00 app[web.1]: at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
2013-08-13T14:43:49.258200+00:00 app[web.1]: at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
2013-08-13T14:43:49.258200+00:00 app[web.1]: Caused by: java.sql.SQLException: Timed out waiting for a free available connection.
2013-08-13T14:43:49.258200+00:00 app[web.1]: at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:503)
2013-08-13T14:43:49.258200+00:00 app[web.1]: at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:114)
2013-08-13T14:43:49.258200+00:00 app[web.1]: at play.db.ebean.EbeanPlugin$WrappingDatasource.getConnection(EbeanPlugin.java:146)
2013-08-13T14:43:49.258200+00:00 app[web.1]: at com.avaje.ebeaninternal.server.transaction.TransactionManager.createQueryTransaction(TransactionManager.java:338)
2013-08-13T14:43:49.258200+00:00 app[web.1]: ... 18 more
正在形成查询但未执行...某些查询可能比其他查询花费更长的时间才能完成,因此不会释放资源?