参与序列制作过程的Akka演员饥饿 [英] Starvation of Akka actors who participate in a sequence process

查看:127
本文介绍了参与序列制作过程的Akka演员饥饿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bisuness逻辑

我们要完成以下业务逻辑:

We have the following business logic to accomplish:

一百万次:


  1. 下载索引为i的文件

  2. 解压缩文件

  3. 从文件中提取一些信息

  4. 删除文件

  1. download the file in index i
  2. unzip the file
  3. extract some info from the file
  4. delete the file

当前的Akka解决方案

我们目前拥有的Akka解决方案会创建100万演员,负责一个文件的下载,一次完成后,他们创建了一个演员来执行第2、3、4步。

The Akka solution that we have at the moment creates 1 million actors who are responsible for one file to download and once they are done they create an actor to take care of steps 2,3,4.

问题

运行该过程后,我们遇到了Akka将下载actor放在首位的情况,而其他actor则处于饥饿状态。

Once we run the process, we came across the situation where the Akka gives top priority to the download actors, and the rest of the actors are beeing in starvation mode.

我们知道随着计算机磁盘已满,因为下载角色不断下载,但是其他角色没有机会扫描和删除文件。

We know that as the machine disk is getting full because the download actors are constantly downloading, but the other actors don't get a chance to scan and delete the files.

问题


  1. 有没有办法迫使Akka不在演员链中饿死演员?

  2. 有没有办法告诉下载actor等待,直到它收到可以继续的通知(例如,磁盘中的并行文件不超过1000个)

谢谢。

推荐答案

为这两种类型使用不同的调度程序演员的角色:

Use different dispatchers for the two types of actor:

在您的配置中,您可以定义一个单独的调度程序,例如:

In your config you can define a separate dispatcher as (for example):

my-dispatcher {
  type = Dispatcher
  executor = "thread-pool-executor"
  thread-pool-executor {
    fixed-pool-size = 32
  }
  throughput = 100
}

您可以在创建时将其分配给特定的参与者:

And then you can assign that to a specific actor at creation:

val myActor = context.actorOf(Props[MyActor].withDispatcher("my-dispatcher"), "myactor1")

实际上,分派器是线程池。将两者分开可以确保缓慢而阻塞的操作不会饿死对方。通常,这种方法称为大量标题,因为这样的想法是,如果应用程序的一部分发生故障,其余部分仍然可以响应。

Dispatchers are, effectively, thread-pools. Separating the two guarantees that the slow, blocking operations don't starve the other. This approach, in general, is referred to as bulk-heading, because the idea is that if a part of the app fails, the rest remains responsive.

有关更多信息,请参见文档

For more info, see the documentation

这篇关于参与序列制作过程的Akka演员饥饿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆