1 year ago

#386014

test-img

giancasveva

AKKA.NET Problems when multiple child actors tell a message to their parent

I'm trying to create a gerarchy of actors like this:

public class Actor1 : UntypedActor
    {
        private int _numberOfChildActive;
        protected override void OnReceive(object message)
        {
            switch (message)
            {
                case "finish":
                    _numberOfChildActive--;
                    if (_numberOfChildActive == 0)
                        Context.Stop(Self);
                    break;
                case int numberOfChild:
                    _numberOfChildActive = numberOfChild;
                    for(int i=0; i < numberOfChild; i++)
                    {
                        Context.ActorOf(Props.Create<Actor2>()).Tell(100000);
                    }
                    break;
            }
        }
    }
    public class Actor2 : UntypedActor
    {
        private int _numberOfChildActive;
        protected override void OnReceive(object message)
        {
            switch (message)
            {
                case "finish":
                    _numberOfChildActive--;
                    if (_numberOfChildActive == 0){
                        Context.Parent.Tell("finish");
                        Context.Stop(Self);
                    }
                    break;
                case int numberOfChild:
                    _numberOfChildActive = numberOfChild;
                    for (int i = 0; i < numberOfChild; i++)
                    {
                        Context.ActorOf(Props.Create<Actor3>()).Tell("start");
                    }
                    break;
            }
        }
    }
    public class Actor3 : UntypedActor
    {
        protected override void OnReceive(object message)
        {
            switch (message)
            {
                case "start":
                    Sender.Tell("finish");
                    Context.Stop(Self);
                    break;
            }
        }
    }
}

When the number of child generated by Actor1 is low, all messagging system work correctly, but if the number of child generate is high ( like the example ) 'Actor1' for a long time don't receive any message and cpu statistic decrease to zero but process memory increase very fast.

Do you know how to solve the problem? Thanks

c#

.net

akka

akka.net

0 Answers

Your Answer

Accepted video resources