简体   繁体   English

阿卡演员优先事项

[英]Akka Actor Priorities

I have an actor-based system that performs periodic, cpu-intensive data ingests as well as serves RESTful endpoints. 我有一个基于actor的系统,它执行定期的,CPU密集的数据摄取以及RESTful端点。 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. 我正在使用Akka演员来发信号/控制摄取过程的各个阶段,而Spray(当然是建立在Akka上)来为我的休息端点提供服务。

My problem is this: When the ingest kicks off it consumes most of the CPU, starving the RESTful endpoints until its done. 我的问题是这样的:当摄取开始时它消耗了大部分CPU,使RESTful端点挨饿直到完成。

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. 现在,摄取和Spray模块共享相同的ActorSystem,但如果这有助于解决方案,它们可以分开。

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) 为CPU密集型演员创建一个新的调度程序,并将Web服务actor留在默认调度程序中(或者,如果您认为合适,也可以将这些调度程序移动到另一个调度程序)

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 您可能想要调整新创建的调度程序 - 例如,如果您说您的摄取演员执行计算密集型作业,您应该将调度程序的并行度降低到接近1.0的值

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. 将您的actor系统分成不同的调度程序可以防止类似于您拥有的问题 - 如果某些actor开始占用底层线程,它们最终会使运行它们的调度程序饱和。 By having the web actors in another dispatcher you limit the impact that the CPU-intensive actors have on the rest of the system. 通过将Web角色放在另一个调度程序中,可以限制CPU密集型角色对系统其余部分的影响。 This is somewhat similar to the concept of "bulkheading" . 这有点类似于“批量”的概念。

Here's some more info on Akka dispatchers: http://doc.akka.io/docs/akka/2.2.0/scala/dispatchers.html 以下是Akka调度员的更多信息: 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 要配置新的调度程序,还需要查看文档的配置部分: http//doc.akka.io/docs/akka/2.2.0/general/configuration.html

There are priority mailboxes that can be built to define which messages are dealt with in which priority. 可以构建优先级邮箱来定义处理哪些消息的优先级。 You can also stash/unstash messages which works nicely with hotswap if you want to stash messages and deal with them once a certain state is encountered. 如果要隐藏消息并在遇到某个状态时处理它们,您还可以存储/解除与hotswap很好地工作的消息。 Info on stash is here: http://doc.akka.io/docs/akka/snapshot/scala/actors.html 关于藏匿的信息在这里: http//doc.akka.io/docs/akka/snapshot/scala/actors.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM