Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Akka have a built-in solution to collect answers from a Broadcast router?

Tags:

java

scala

akka

   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 send 1000000 cars an message to answer me which are "green"? And I expect 50000 cars to answer "yes" and the rest (950000) to answer "no"

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

But what is the fastest way to collect the 50000 "green" answers?

Does Akka have a built-in solution?

(It may be best to collect the answers in parallel and not just with a single actor?)

like image 495
jack Avatar asked Dec 02 '25 09:12

jack


1 Answers

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

If you need to aggregate them (which it sounds like you do), that would eventually need to happen in one actor. This means that your 1 million answers will all queue up on the single actor and it will become a hotspot.

If you can tolerate slightly slower reads, another possibility is to have multiple counter actors, which are themselves part of a router (lets say RoundRobin for now). This divides up the counting to multiple actors, but now to get the real total count you would have to ask all of the actors and aggregate them at read time. This strategy could be beneficial if you want to record a lot of "answers", but only read them occasionally when latency may be less important.

like image 58
pkohan Avatar answered Dec 04 '25 23:12

pkohan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!