简体   繁体   English

Akka演员正在停止

[英]Akka actors are getting stopped

I'm using akka actors to achieve parallel processing of some http requests. 我正在使用Akka actor来实现对某些http请求的并行处理。 I've initailized a pool of actors using RoundRobinPool like: 我使用RoundRobinPoolRoundRobinPool演员池,例如:

ActorRef myActorPool = actorSystem.actorOf(new RoundRobinPool(200).props(Props.create(MyActor.class, args)), MyActor.class.getSimpleName());

It is working fine. 一切正常。 But after the process is running for sometime, i'm getting following error 但是在该程序运行了一段时间后,出现以下错误

java.util.concurrent.CompletionException: akka.pattern.AskTimeoutException: Recipient[Actor[akka://web_server/user/MyActor#-769383443]] had already been terminated. java.util.concurrent.CompletionException:akka.pattern.AskTimeoutException:Recipient [Actor [akka:// web_server / user / MyActor#-769383443]]已被终止。 Sender[null] sent the message of type "com.data.model.Request". Sender [null]发送了类型为“ com.data.model.Request”的消息。

So I've overridden postStop method added a log statement there. 因此,我重写了postStop方法,并在其中添加了一条日志语句。

@Override
public void postStop() {
    log.warn("Actor is stopped");
}

Now, I can see in the logs that the actors are getting stopped. 现在,我可以在日志中看到参与者正在停止。 But I'm not sure for which request it is happening. 但是我不确定它是针对哪个请求的。 Once all the actors in the pool terminates (200 is the pool size I've set), I'm getting AskTimeoutException as said before. 一旦池中的所有参与者终止(我设置的池大小为200),我将得到AskTimeoutException Is there anyway to debug why the actors are getting terminated? 无论如何,有没有调试演员为什么被解雇的原因?

EDIT 1 编辑1

In the controller, I'm using the created actor pool like 在控制器中,我使用的是像

CompletableFuture<Object> s = ask(myActorPool, request, 1000000000).toCompletableFuture();
return s.join();

The actor processes one kind of messages only. 参与者仅处理一种消息。

@Override
public AbstractActor.Receive createReceive() {
    return receiveBuilder()
            .match(Request.class, this::process)
            .build();
}

private void process(Request request) {
    try {
        // code here
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        getSender().tell(new akka.actor.Status.Failure(e), getSelf());
    }
}

As far as you have described the probelm it seems you are processing your data inside the ask call and taking more time than askTimeout, and you are getting the error. 就描述探针而言,似乎您正在Ask呼叫内处理数据,并且花费的时间比askTimeout多,并且您正在收到错误。

What you can do is either increase the askTimeout or do less processing inside tha ask call. 您可以做的是增加askTimeout或在Ask呼叫内进行更少的处理。

you should not do CPU bound operations inside the ask call, it can cause slowing down your system it is recommended that you should do the I/O bound operations inside the ask call. 您不应在Ask调用内执行CPU绑定操作,否则可能导致系统变慢,建议您在Ask调用内执行I / O绑定操作。 That way you can leverage the actors. 这样,您可以利用演员。

For example: 例如:

val x=x+1   // CPU bound operation should not do inside the ask call

some db call you can do inside the ask call that is preferable. 您可以在Ask调用内执行一些数据库调用,这是更好的选择。

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

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