2016-05-03 63 views
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) 

我的问题是:

  1. 这是我创建的io-dispatcher线程池,是否仅用于Actor的?我的目的是为我的流使用这个线程池,这些流由Actor的一个实例化。然后我将这个线程池传递给我的流。

  2. 如何通过从application.conf中加载调度程序来创建ExecutionContext?我应该使用任何特定的库来读取我的线程池配置并给我一个ExecutionContext?

回答

1

该配置是正确的。您所需要做的就是将加载的配置文件传递到Akka ActorSystem,如:

ActorSystem("yourActorSystem", ConfigFactory.load())