【问题标题】:Ignoring Async Wait for a Play! Scala App in New Relic忽略异步等待播放! New Relic 中的 Scala 应用程序
【发布时间】:2014-01-21 15:00:32
【问题描述】:

在我的游戏中! 2.1 Rest API App 我已经安装了New Relic。

我所有的控制器动作都继承自一个为响应的未来添加超时的方法。如果任何此类方法花费的时间超过 20 秒,则请求将终止,结果为 5XX 错误。

代码基本上是这样的:

val timeout = 20

action(request).orTimeout(
     name + " backend timed-out after "+timeout+" seconds", timeout * 1000).map { 
     resultOrTimeout => { //... process response or timeout with fold

我遇到的问题是,在分析新文物中的数据时,我总是得到 20 秒的平均响应时间。

查看跟踪时,我可以看到 new relic 将超时函数解释为响应的容器。

Slowest components                         Count    Duration    %
Async Wait                                  7       20,000 ms   100%
Action$$anonfun$apply$1.apply()             2       2 ms         0%
PlayDefaultUpstreamHandler$$an....apply()     1       1 ms         0%
PlayDefaultUpstream....$$anonfun$24.apply() 1      1 ms         0%
SmaugController$class.akkify()               1       0 ms         0%
PlayDefaultUpstreamHandler.handleAction$1() 1       0 ms          0%
Total                                               20,000 ms   100%

有什么办法可以防止 new-relic 考虑超时?

谢谢!

编辑:我扩展了交易以获取更多信息:

Duration (ms)   Duration (%)    Segment Drilldown   Timestamp
20,000  100.00%    HttpRequestDecoder.unfoldAndFireMessageReceived()
20,000  100.00%    Async Wait
Stack trace

scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23)
      java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1146)

     java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)

                                   java.lang.Thread.run (Thread.java:679)

107  0.53%   SmaugController$class.akkify() 

如您所见,真正的工作是在 akkify 方法中完成的,耗时 107 毫秒,其余的都被 Async Wait 调用消耗

【问题讨论】:

    标签: asynchronous playframework-2.0 scala-2.10 newrelic


    【解决方案1】:

    很遗憾,目前无法忽略 New Relic 中的特定超时。

    但是,New Relic Java 代理的 3.4.1 版本支持 Play 2.2.1 中记录的句柄超时示例代码:http://www.playframework.com/documentation/2.2.1/ScalaAsync

    你可以在这里下载:https://download.newrelic.com/newrelic/java-agent/newrelic-agent/3.4.1/

    import play.api.libs.concurrent.Execution.Implicits.defaultContext
    import scala.concurrent.duration._
    
    def index = Action.async {
      val futureInt = scala.concurrent.Future { intensiveComputation() }
      val timeoutFuture = play.api.libs.concurrent.Promise.timeout("Oops", 1.second)
      Future.firstCompletedOf(Seq(futureInt, timeoutFuture)).map {
        case i: Int => Ok("Got result: " + i)
        case t: String => InternalServerError(t)
      }
    }
    

    【讨论】:

    • 最终它与 Play 2.1.1 一起使用。重要的是 Promise.timeout 和 Future.firstCompletedOf 方法。新遗物不需要 Action.async 方法正确报告时间。
    猜你喜欢
    • 2014-11-30
    • 1970-01-01
    • 2021-09-10
    • 2012-11-09
    • 2015-04-09
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多