如何为Akka HTTP设置调度程序/线程池

时间:2018-09-08 14:38:32

标签: scala akka akka-http

我对akka-http有疑问。我已经开发了一种服务,它可以分解不同的参与者,除了一些其他任务之外,一些参与者还通过akka-http Http()。singleRequest函数对不同的端点进行外部http调用。我想通过单独的调度程序池/配置隔离Http调用,但是我找不到定义调度程序的方法。对于其他参与者,我可以通过.withDispatcher()方法进行定义。据我所知(通过actor实现器),Akka-http正在通过akka流运行,但是如何为Http()。singleRequest函数定义调度程序?

谢谢!

1 个答案:

答案 0 :(得分:1)

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

实际上,在定义了调度程序之后,您可以将该调度程序用于执行外部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
}
相关问题