本文介绍了Akka演员优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于actor的系统,该系统执行周期性的,CPU密集型数据提取,并为RESTful端点提供服务。我正在使用Akka演员来发信号/控制摄取过程的各个阶段,并使用Spray(当然是在Akka上构建的)来服务我的宁静端点。

I have an actor-based system that performs periodic, cpu-intensive data ingests as well as serves RESTful endpoints. I'm using Akka actors to signal/control the various stages of the ingest process, and Spray (which is of course built on Akka) to serve my restful endpoints.

我的问题是:开始执行摄取操作时,它会消耗大量CPU,使RESTful端点饿死直到完成。

My problem is this: When the ingest kicks off it consumes most of the CPU, starving the RESTful endpoints until its done.

降低优先级的最佳方法是什么摄取?现在,摄取和Spray模块共享相同的ActorSystem,但是如果有帮助的话,可以将它们分开。

What's the best way to lower the priority of the ingest? Right now the ingest and the Spray module share the same ActorSystem, but they could be separated if that helps the solution.

推荐答案

它您系统中的不同参与者似乎需要住在不同的调度程序中。为CPU密集型角色创建一个新的调度程序,并将Web服务角色保留在默认的调度程序中(或者,如果您认为合适的话,也可以将它们移动到另一个调度程序)

It seems the different actors in your system need to live in different dispatchers. Create a new dispatcher for the CPU-intensive actors and leave the web service actors in the default dispatcher (or maybe move those to another dispatcher as well, if you see fit)

您可能需要调整新创建的调度程序-例如,如果您说摄取角色执行计算密集型工作,则应将调度程序的并行度降低到接近1.0的水平

You may want to tweak the newly created dispatcher - for example, if you say your ingest actors perform computationally intensive jobs you should reduce the degree of parallelism of the dispatcher to something closer to 1.0

将actor系统分成不同的调度程序可以防止出现与您遇到的问题类似的问题-如果某些actor开始占用底层线程,则它们最终会使运行它们的调度程序饱和。通过将Web actor放在另一个调度程序中,您可以限制CPU密集型actor对系统其余部分的影响。这有点类似于的概念。

Separating your actor system into different dispatchers prevents problems similar to the one you have - if some actors start to hog the underlying threads they end up saturating the dispatcher that runs them. By having the web actors in another dispatcher you limit the impact that the CPU-intensive actors have on the rest of the system. This is somewhat similar to the concept of "bulkheading".

以下是有关Akka调度程序的更多信息:

Here's some more info on Akka dispatchers:http://doc.akka.io/docs/akka/2.2.0/scala/dispatchers.html

到配置新的调度程序,还值得看看文档的配置部分:

To configure new dispatcher it's also worthwhile to take a look at the configuration section of the documentation:http://doc.akka.io/docs/akka/2.2.0/general/configuration.html

这篇关于Akka演员优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:24