如何为akka http设置调度程序/线程池

How to set dispatcher / thread pool for akka http

我有一个关于 akka-http 的问题。我开发了一项服务,它正在启动不同的参与者,除了一些其他任务之外,一些参与者还通过 akka-http Http().singleRequest 函数对不同的端点进行外部 http 调用。我想通过单独的调度程序 pool/configuration 隔离 Http 调用,但我找不到定义调度程序的方法。对于其他演员,我可以通过 .withDispatcher() 方法来定义它。据我所知,Akka-http 运行 通过 akka 流(通过 actor 实体化器),但是我如何为 Http().singleRequest 函数定义调度程序?

提前致谢!

您可以在您的 conf 文件中定义您的调度程序。 有关更多信息,请阅读给定 link 中的 akka 文档。 调度程序实现 ExecutionContext 接口,因此可用于 运行 未来调用等

实际上在定义调度程序之后,您可以将该调度程序用于执行外部调用的 actor API 并通过调度程序为他们提供执行上下文。

https://doc.akka.io/docs/akka/2.5/dispatchers.html

它有这样的结构:

my-dispatcher {
  # Dispatcher is the name of the event-based dispatcher
  type = Dispatcher
  # What kind of ExecutionService to use
  executor = "fork-join-executor"
  # Configuration for the fork join pool
  fork-join-executor {
    # Min number of threads to cap factor-based parallelism number to
    parallelism-min = 2
    # Parallelism (threads) ... ceil(available processors * factor)
    parallelism-factor = 2.0
    # Max number of threads to cap factor-based parallelism number to
    parallelism-max = 10
  }
  # Throughput defines the maximum number of messages to be
  # processed per actor before the thread jumps to the next actor.
  # Set to 1 for as fair as possible.
  throughput = 100
}