akka-streams + akka actors : mapAsyncUnordered + ask Pattern issue

249 Views Asked by At

I have been working with akka-actors and akka-cluster for a while now. Recently, I had a requirement of adding backpressure to the code and used akka-streams native pattern mapAsyncUnordered + ask ( order of messages do not matter ) to solve this issue.

public class A extends AbstractActor {
    public Receive createReceive() {
        return receiveBuilder()
                .match(String.class, this::start)
                .build()
    }

    private void start(String msg){
        getSender().tell(1,getSelf()); // acknowledgement for ask()
        List<String> x = new ArrayList<>();
        for(String h : children)
            x.add(h);
        Source.from(x)
            .mapAsyncUnordered(2, s -> ask(getSelf(),s,askTimeout))
            .runWith(Sink.ignore(), mat);
    }
}

Problem is similar to exploring a tree.

If the tree is small this seems to work fine. But if the tree increases in size, the code seems to be stuck and not running. Tree might be as big as 100 million nodes or even more.

Can someone help me on how to make it working or suggest a better way of doing so.

0

There are 0 best solutions below