Akka参考通过Play Framework不断增加

问题描述

几周前,我已将应用程序中的所有多线程操作更改为Akka。 但是,由于似乎我已经开始用完堆空间(大约一周后)。

基本上看所有演员与

ActorSelection selection = getContext().actorSelection("/*");

演员的人数似乎一直在增加。经过一个小时的运行,我得到了超过2200的称呼。

akka://application/user/$Aic
akka://application/user/$Alb
akka://application/user/$Alc
akka://application/user/$Am
akka://application/user/$Amb

我还注意到,打开websocket(并关闭它们)时,这些是:

akka://application/system/Materializers/StreamSupervisor-2/flow-21-0-unnamed
akka://application/system/Materializers/StreamSupervisor-2/flow-2-0-unnamed
akka://application/system/Materializers/StreamSupervisor-2/flow-27-0-unnamed
akka://application/system/Materializers/StreamSupervisor-2/flow-23-0-unnamed

我需要关闭它们并清洁它们吗?

我不确定是否与内存问题有关,但是一个小时后,生产服务器上似乎有太多这样的事实。

[编辑:添加了用于分析/计算演员的代码]

public class RetrieveActors extends AbstractActor {

    private String identifyId;
    private List<String> list;

    public RetrieveActors(String identifyId) {
        Logger.debug("Actor retriever identity: " + identifyId);
        this.identifyId = identifyId;
    }

    @Override
    public Receive createReceive() {
        Logger.info("RetrieveActors");
        return receiveBuilder()
                .match(String.class,request -> {
                    //Logger.info("Message: " + request + " " + new Date());
                    if(request.equalsIgnoreCase("run")) {
                        list = new ArrayList<>();
                        ActorSelection selection = getContext().actorSelection("/*");
                        selection.tell(new Identify(identifyId),getSelf());
                        //ask(selection,new Identify(identifyId),1000).thenApply(response -> (Object) response).toCompletableFuture().get();
                    } else if(request.equalsIgnoreCase("result")) {
                        //Logger.debug("Run list: " + list + " " + new Date());
                        sender().tell(list,self());
                    } else {
                        sender().tell("Wrong command: " + request,self());
                    }
                }).match(ActorIdentity.class,identity -> {
                    if (identity.correlationId().equals(identifyId)) {
                        ActorRef ref = identity.getActorRef().orElse(null);
                        if (ref != null) { // to avoid NullPointerExceptions
                            // Log or store the identity of the actor who replied
                            //Logger.info("The actor " + ref.path().toString() + " exists and has replied!");
                            list.add(ref.path().toString());
                            // We want to discover all children of the received actor (recursive traversal)
                            ActorSelection selection = getContext().actorSelection(ref.path().toString() + "/*");
                            selection.tell(new Identify(identifyId),getSelf());
                        }

                    }
                    sender().tell(list.toString(),self());
                }).build();
    }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)