代码之家  ›  专栏  ›  技术社区  ›  Avba

Akka Http JSON序列化非常慢

  •  0
  • Avba  · 技术社区  · 7 年前

    case class Response(msg: String)
    implicit val format = jsonFormat(Response)
    
    
    def logMagnet()(t: LoggingAdapter): HttpRequest => RouteResult => Unit = {
        request => {
          val startTime = System.currentTimeMillis()
          response => {
            val total = System.currentTimeMillis() - startTime
            logger.info("took $total")
          }
        }
      }
    
    val route = logRequestResult(LoggingMagnet(logMagnet())) {
       val start = System.currentTimeMillis()
       val calculateSomethings = ....
       val duration = System.currentTimeMillis() - start
       val response = Response("took $duration to calculate")
       complete(response)
    }
    

    对于琐碎的序列化,记录到响应之间的时间通常为3-4毫秒。

    0 回复  |  直到 7 年前