akka 设置Actor的调度程序
示例
因此,如果要为Actor提供与默认调度程序不同的调度程序,则需要做两件事,首先是在您的服务器中配置调度程序application.conf:
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
}这是另一个使用“thread-pool-executor”的示例:
my-thread-pool-dispatcher {
# Dispatcher is the name of the event-based dispatcher
type = Dispatcher
# What kind of ExecutionService to use
executor = "thread-pool-executor"
# Configuration for the thread pool
thread-pool-executor {
# minimum number of threads to cap factor-based core number to
core-pool-size-min = 2
# No of core threads ... ceil(available processors * factor)
core-pool-size-factor = 2.0
# maximum number of threads to cap factor-based number to
core-pool-size-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
}然后,您可以在配置中定义要用于您的actor的调度程序,例如
akka.actor.deployment {
/myactor {
dispatcher = my-dispatcher
}
}并使用配置中指定的名称创建此actor:
import akka.actor.Props val myActor = context.actorOf(Props[MyActor], "myactor")
或者,您可以使用以下命令查找调度员:
import akka.actor.Props
val myActor =
context.actorOf(Props[MyActor].withDispatcher("my-dispatcher"), "myactor1")
热门推荐
10 唯美的祝福语简短的
11 诗词文案祝福语简短精辟
12 简短朋友旅行祝福语大全
13 新疆新年祝福语大全简短
14 聚餐会祝福语简短
15 姐妹结婚快乐祝福语简短
16 爱情祝福语大全 简短实际
17 许愿星姐妹祝福语简短
18 祖国七十华诞简短祝福语