Does Akka have a built-in solution for collecting responses from a broadcast router?

   List<String> paths = Arrays.asList("/user/cars/*");
   ActorRef router =
   getContext().actorOf(new BroadcastGroup(paths).props(), "router");

   router.tell("which cars are green")

      

With the above code, I am sending 1,000,000 vehicles a message to reply to me, which are "green"? And also I expect 50,000 cars to answer "yes" and the rest (950,000) to answer "no"

I think with a broadcast router I am doing the most efficient way to query cars.

But what is the fastest way to get 50,000 green responses?

Does Akka have a built-in solution?

(Is it best to collect responses in parallel, not just one actor?)

+3


source to share


1 answer


The answer depends on what you mean by "collecting" the answers.

If you need to fill them in (which is similar to what you are doing), this should eventually happen in a single actor. This means that your 1 million responses will be queuing up per actor, and it will become a hot spot.



If you can tolerate slightly slower reads, another possibility is to have multiple counters that are themselves part of a router (say RoundRobin). This divides the bill into multiple members, but now, to get a real total bill, you will need to ask all members and combine them while reading. This strategy can be useful if you want to record many "responses" but only read them from time to time when latency may be less important.

+3


source







All Articles