11

I have successfully sent work to a pool of actors to perform my work, but now I want to do some aggregation on the results returned by all the workers. How do I know that everyone is done?

The best I have come up with is to maintain a set of requests ids and wait for that set to go to zero, but this seems inelegant.

Damian
  • 2,509
  • 24
  • 35

1 Answers1

10

Generally, you want to use what we call the "Commander" pattern for this. Essentially, you have one stateful actor (the Commander) that is responsible for starting and monitoring the task. You then farm out the actual work across the actor pool, and have them report back to the Commander as they finish. The commander can then track the progress of the job by calculating # completions / size of worker pool.

This way, the workers can be monitored and restarted independently as they do the work, but all the precious task-level state and information lives in the Commander (this is called the "Error Kernel pattern")

You can see an example of this in the Akka.NET scalable webcrawler demo.

AndrewS
  • 1,365
  • 10
  • 23
  • 1
    Thanks. This sounds like essentially what I ended up doing. I had a stateful actor that is coordinating everything and it farms out work and keeps track of responses. The docs you guys have produced as of late are second to none. Thanks! – Damian May 06 '15 at 21:28
  • in the case, "commander" should **wait** completion on all child? if not, the "commander" **cannot be executed twice** at the same time? – constructor Jun 17 '15 at 05:00
  • @constructor You can get around that limitation by creating a pool of your commanders. Then you just send work to your pool, and it will load balance the work between the commander actors. (The commander actors can also be stateful, i.e. `Become(Busy)` or `Become(Ready)`, and decide to `Stash` new work requests until they they are `Ready` to process them, etc. – BrainSlugs83 Aug 19 '15 at 21:19
  • Do you have any references on this "Commander" pattern? Googling for `akka "commander pattern"` returns only 31 results. – user247702 Jul 20 '17 at 08:46