0
我有一個基於Spray的HTTP服務。我有一個流在這個HTTP應用程序中運行。現在,由於這個流做了很多I/O,我決定使用一個單獨的線程池。我查閱了Akka文檔,看看我能做些什麼,以便我的線程池可配置。我遇到了Akka的Dispatcher概念。於是,我就在我的application.conf如下使用它:使用Akka調度員處理期貨
akka {
io-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 = 20
}
}
在我的演員,我試圖查找該配置爲:
context.system.dispatchers.lookup("akka.io-dispatcher")
當我跑我的服務,我得到以下錯誤:
[ERROR] [05/03/2016 12:59:08.673] [my-app-akka.actor.default-dispatcher-2] [akka://my-app/user/myAppSupervisorActor] Dispatcher [akka.io-dispatcher] not configured
akka.ConfigurationException: Dispatcher [akka.io-dispatcher] not configured
at akka.dispatch.Dispatchers.lookupConfigurator(Dispatchers.scala:99)
at akka.dispatch.Dispatchers.lookup(Dispatchers.scala:81)
我的問題是:
這是我創建的io-dispatcher線程池,是否僅用於Actor的?我的目的是爲我的流使用這個線程池,這些流由Actor的一個實例化。然後我將這個線程池傳遞給我的流。
如何通過從application.conf中加載調度程序來創建ExecutionContext?我應該使用任何特定的庫來讀取我的線程池配置並給我一個ExecutionContext?