玩框架挂

Play framework hanging

与中的问题相关 Rest server (Play Framework) gets "Read Timed out" exception during load test

我在使用 play framework 2.2.4 时遇到了类似的情况:

java 版本“1.8.0_31” Java(TM) SE 运行时环境(build 1.8.0_31-b13) Java HotSpot(TM) 64 位服务器 VM(内部版本 25.31-b07,混合模式)

我正在本地 PC 上测试 jmeter。我遇到了 2000 个线程并发生超时异常,并且 Socket 不知何故没有关闭。

如何捕获此异常并关闭挂起的套接字?
堆栈跟踪:

va.util.concurrent.TimeoutException: Futures timed out after [5 seconds]
        at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219) [scala-library.jar:na]
        at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223) [scala-library.jar:na]
        at scala.concurrent.Await$$anonfun$result.apply(package.scala:107) ~[scala-library.jar:na]
        at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread$$anon.block(ThreadPoolBuilder.scala:169) ~[akka-actor_2.10.jar:2.2.0]
        at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:3640) [scala-library.jar:na]
        at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread.blockOn(ThreadPoolBuilder.scala:167) ~[akka-actor_2.10.jar:2.2.0]
        at scala.concurrent.Await$.result(package.scala:107) ~[scala-library.jar:na]
        at play.core.j.FPromiseHelper$.get(FPromiseHelper.scala:53) ~[play_2.10.jar:2.2.4]
        at play.core.j.FPromiseHelper.get(FPromiseHelper.scala) ~[play_2.10.jar:2.2.4]
        at play.libs.F$Promise.get(F.java:363) ~[play_2.10.jar:2.2.4]
wrap response>>
        at com.ganda.common.controllers.filters.WrapResponse.wrap(WrapResponse.java:50) ~[na:na]
db filter below>>>
        at com.ganda.common.controllers.filters.CredentialsFilter.call(CredentialsFilter.java:72) ~[na:na]
        at play.core.j.JavaAction$$anon.apply(JavaAction.scala:91) ~[play_2.10.jar:2.2.4]
        at play.core.j.JavaAction$$anon.apply(JavaAction.scala:90) ~[play_2.10.jar:2.2.4]
        at play.core.j.FPromiseHelper$$anonfun$flatMap.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.4]
        at play.core.j.FPromiseHelper$$anonfun$flatMap.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.4]
        at scala.concurrent.Future$$anonfun$flatMap.apply(Future.scala:251) ~[scala-library.jar:na]
        at scala.concurrent.Future$$anonfun$flatMap.apply(Future.scala:249) ~[scala-library.jar:na]
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
        at play.core.j.HttpExecutionContext$$anon.run(HttpExecutionContext.scala:37) ~[play_2.10.jar:2.2.4]
        at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42) ~[akka-actor_2.10.jar:2.2.0]
        at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) ~[akka-actor_2.10.jar:2.2.0]
Wrapped by: play.api.Application$$anon: Execution exception[[TimeoutException: Futures timed out after [5 seconds]]]
        at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.4]
        at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.4]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$$anonfun$applyOrElse.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.4]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$$anonfun$applyOrElse.apply(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.4]
        at scala.Option.map(Option.scala:145) [scala-library.jar:na]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.4]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun.applyOrElse(PlayDefaultUpstreamHandler.scala:260) [play_2.10.jar:2.2.4]
        at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:344) [scala-library.jar:na]
        at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:343) [scala-library.jar:na]
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
        at play.api.libs.iteratee.Execution$$anon.execute(Execution.scala:43) [play-iteratees_2.10.jar:2.2.4]
        at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [scala-library.jar:na]
        at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [scala-library.jar:na]
        at scala.concurrent.Promise$class.complete(Promise.scala:55) [scala-library.jar:na]
        at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [scala-library.jar:na]
        at scala.concurrent.Future$$anonfun$map.apply(Future.scala:235) [scala-library.jar:na]
        at scala.concurrent.Future$$anonfun$map.apply(Future.scala:235) [scala-library.jar:na]
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
        at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1361) [scala-library.jar:na]
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library.jar:na]
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library.jar:na]

这里发生的是 Play promise 超时,可能是由于加载导致速度变慢。

所以这揭示了您的应用程序中的性能问题,如果可以接受,您可以增加承诺超时或配置文件并提高承诺处理的性能,以便它进行得更快。