简体   繁体   English

Akka演员阻止消息

[英]Akka actors blocking messages

Hi since i am unable to address the problem correctly this may not be the proper title for my question but here is the case ; 嗨,由于我无法正确解决问题,这可能不是我所提问题的正确标题,但实际情况是这样;

Actor A creates Actor B1 and Actor B1 creates "n" actors which are responsible for execiting tasks. 演员A创建演员B1,而演员B1创建负责执行任务的“ n”个演员。 So A is parent of B1 and B1 is parent of lets say b1, b2, b3, .... 因此,A是B1的父级,而B1是b1,b2,b3,...的父级。

In A i have scheduled a ticker so that A checks every 10secods if there is a new B' to create. 在A中,我安排了一个股票行情,以便A每10秒检查一次是否有新的B'要创建。

Duration duration = Duration.create(10 sec.);
FiniteDuration interval = new FiniteDuration(duration.toMillis(), TimeUnit.MILLISECONDS);
ticker = getContext().system().scheduler().schedule(interval, interval, getSelf(), new Tick() { }, getContext().dispatcher(), getSelf());

On front end i can adjust the parallel degree of number of "b" tasks. 在前端,我可以调整“ b”个任务的并行度。 For example if i set the parallel degree to 3 then B(1) creates 3 actors and each actor executes some task and if one actor , lets say b(n), finishes than b(n+1) is created and so on. 例如,如果我将并行度设置为3,则B(1)创建3个actor,每个actor执行某个任务,如果一个actor,使b(n)结束,则创建b(n + 1),依此类推。

The problem is ; 问题是 ;

If there is only one actor b(i=1) that is created by Actor "B'" (which B is not important) than ticker really ticks every 10 seconds, but if i increase the parallel degree of b's to lets say 64 b(i=64) then tickers doesnot behave properley. 如果只有一个由演员“ B'”创建的演员b(i = 1)(该B不重要),则记号器会每10秒真正滴答一声,但是如果我将b的平行度提高到64 b (i = 64),则股票行情不会表现得很好。 It waits quite a long time for example 1 min. 它等待相当长的时间,例如1分钟。 then ticks 6 times consequtively as if there is a flush mechanisim. 然后滴答作响6次,好像有一个冲洗机械。

And this is not the only problem i got when i increase the number of actors on the system. 当我增加系统参与者的数量时,这不是我遇到的唯一问题。

I have a api so that user sends orders to actors like below 我有一个api,以便用户将订单发送给演员,如下所示

String path = ActorPaths.actorPathForPlan(plan);
ActorSelection actorSelection = runtimeInit.getSystem().actorSelection(path);
// ask
Timeout timeout = new Timeout(Duration.create(4*1000, TimeUnit.MILLISECONDS));
Future<Object> future = Patterns.ask(actorSelection, message, timeout);
// get result
return returnType.cast(Await.result(future, timeout.duration()));

when there is more than approximitely 10 actors then futures always times out but when i debug the code i see the message is recived but after quite a long time. 当大约有10个参与者时,期货总是超时,但是当我调试代码时,我看到消息已接收,但是经过了很长一段时间。

So, I wonder what is blocking my Actor A from receiving messages. 因此,我想知道是什么阻止了Actor A接收消息。 The same problem may be occuring in actor B' and its children i didn't checked yet but if i figure out the problem i belive i can apply the solution to others. 同样的问题可能发生在演员B'及其孩子中,但我尚未检查过,但是如果我发现问题,我相信我可以将解决方案应用于其他对象。

Thanks for any suggestions. 感谢您的任何建议。

The hiararchy is like this 层次结构是这样的

http://i.stack.imgur.com/PRmwE.png http://i.stack.imgur.com/PRmwE.png

By default all Akka actors use the same executor which is limited to use 64 threads maximum. 默认情况下,所有Akka参与者都使用同一执行器,该执行器最多只能使用64个线程。 From http://doc.akka.io/docs/akka/snapshot/general/configuration.html : http://doc.akka.io/docs/akka/snapshot/general/configuration.html

# This will be used if you have set "executor = "default-executor"".
      # If an ActorSystem is created with a given ExecutionContext, this
      # ExecutionContext will be used as the default executor for all
      # dispatchers in the ActorSystem configured with
      # executor = "default-executor". Note that "default-executor"
      # is the default value for executor, and therefore used if not
      # specified otherwise. If no ExecutionContext is given,
      # the executor configured in "fallback" will be used.
      default-executor {
        fallback = "fork-join-executor"
      }

      # This will be used if you have set "executor = "fork-join-executor""
      fork-join-executor {
        # Min number of threads to cap factor-based parallelism number to
        parallelism-min = 8

        # The parallelism factor is used to determine thread pool size using the
        # following formula: ceil(available processors * factor). Resulting size
        # is then bounded by the parallelism-min and parallelism-max values.
        parallelism-factor = 3.0

        # Max number of threads to cap factor-based parallelism number to
        parallelism-max = 64
      }

The problem is likely related to blocking calls in b* actors. 问题可能与阻止b * actor中的调用有关。 Akka assigns separate threads from a pool of 64 to handle these blocking calls in b* actors and waits for one of them to complete message processing to be able to handle messages for A and B. Akka从64个池中分配单独的线程来处理b * actor中的这些阻塞调用,并等待它们中的一个完成消息处理,以便能够处理A和B的消息。

See "Blocking Needs Careful Management" in http://doc.akka.io/docs/akka/snapshot/general/actor-systems.html for ideas how to work around this issue. 有关如何解决此问题的想法,请参阅http://doc.akka.io/docs/akka/snapshot/general/actor-systems.html中的 “阻止需要仔细管理”。

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

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