我创建了一个使用Akka和RoundRobin路由器的应用程序。应用程序获取文件列表并并行处理它们。我的问题是,无论我指定多少工作线程,应用程序一次只能处理 12 个文件。我需要更改某个设置吗?
val workers = context.actorOf(Props[ItemProcessingWorker].withRouter(RoundRobinRouter(nworkers)))
更新:我试图通过编程方式通过配置发送参数..仍然不起作用。
val conf1 = ConfigFactory.load(ConfigFactory.parseString("""
akka {
default-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 = 32
# Parallelism (threads) ... ceil(available processors * factor)
parallelism-factor = 1.0
# Max number of threads to cap factor-based parallelism number to
parallelism-max = 32
}
# 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 = 1000
}}
"""))
val system = ActorSystem("MySystem2",conf1)
在resources/application.conf
中尝试更改default-dispatcher
的值
akka {
default-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 = 16
# Parallelism (threads) ... ceil(available processors * factor)
parallelism-factor = 2.0
# Max number of threads to cap factor-based parallelism number to
parallelism-max = 32
}
# 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
}
}
好的,我解决了这个问题,我缺少子配置而不是
akka {
default-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
throughput = 1000
fork-join-executor {
parallelism-min = 32
parallelism-factor = 0.5
parallelism-max = 64
}
}
}
它应该是
akka {
actor{
default-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
throughput = 1000
fork-join-executor {
parallelism-min = 32
parallelism-factor = 0.5
parallelism-max = 64
}
}
}
}