Akka http 服务器调度程序数量不断增加

Akka http server dispatcher number constantly increasing

我正在 AWS ECS 上测试 akka http 服务。每个实例都被添加到一个负载均衡器中,该负载均衡器定期向健康检查路由发出请求。由于这是一个测试环境,我无法控制其他流量进入服务器。我注意到调试日志表明 "default dispatcher" 数字一直在增加:

[DEBUG] [01/03/2017 22:33:03.007] [default-akka.actor.default-dispatcher-41200] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted
[DEBUG] [01/03/2017 22:33:29.142] [default-akka.actor.default-dispatcher-41196] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted
[DEBUG] [01/03/2017 22:33:33.035] [default-akka.actor.default-dispatcher-41204] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted
[DEBUG] [01/03/2017 22:33:59.174] [default-akka.actor.default-dispatcher-41187] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted
[DEBUG] [01/03/2017 22:34:03.066] [default-akka.actor.default-dispatcher-41186] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted
[DEBUG] [01/03/2017 22:34:29.204] [default-akka.actor.default-dispatcher-41179] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted
[DEBUG] [01/03/2017 22:34:33.097] [default-akka.actor.default-dispatcher-41210] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted

这种趋势永远不会逆转,很快就会达到数万。这是正常行为还是表明存在问题?

编辑: 我更新了日志片段以显示调度程序线程数超出了我的预期。

编辑#2:健康检查路由代码如下:

class HealthCheckRoutes()(implicit executionContext: ExecutionContext)
  extends LogHelper {

  val routes = pathPrefix("health-check") {
    pathEndOrSingleSlash {
      complete(OK -> "Ok")
    }
  }
}

可能是的。我认为这是线程名称。

如果你在服务器上a thread dump,它是否有很多打开的线程?

您的服务器似乎在为每个连接泄漏一个线程。

(在您的开发机器上进行调试和诊断可能比在 EC2 VM 上更容易。尝试在本地重现它。)

对于您的问题,请查看此评论:

关于调度员:

使用默认调度器进行健康检查等操作是没有问题的。

线程由您指定的调度程序控制,如果未指定,则由 default-dispatcher 控制。 default-dispatcher设置如下,这意味着线程池大小在8到64之间等于(数量处理器 * 3).

default-dispatcher {
  type = "Dispatcher"

  executor = "default-executor"

  default-executor {
    fallback = "fork-join-executor"
  }

  fork-join-executor {
    # Min number of threads to cap factor-based parallelism number to
    parallelism-min = 8

    # The parallelism factor is used to determine thread pool size using the
    # following formula: ceil(available processors * factor). Resulting size
    # is then bounded by the parallelism-min and parallelism-max values.
    parallelism-factor = 3.0

    # Max number of threads to cap factor-based parallelism number to
    parallelism-max = 64

    # Setting to "FIFO" to use queue like peeking mode which "poll" or "LIFO" to use stack
    # like peeking mode which "pop".
    task-peeking-mode = "FIFO"
  }

调度员文档: http://doc.akka.io/docs/akka/2.4.16/scala/dispatchers.html

配置参考: http://doc.akka.io/docs/akka/2.4.16/general/configuration.html#akka-actor

顺便说一句,操作需要很长时间并阻止其他操作,这里是如何在 Akka HTTP 中为它们指定自定义调度程序: http://doc.akka.io/docs/akka-http/current/scala/http/handling-blocking-operations-in-akka-http-routes.html

根据这个 akka-http github 问题似乎没有问题:https://github.com/akka/akka-http/issues/722