我如何等待Akka.Net中的所有工作完成?

时间:2022-10-30 10:42:05

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.

我提出的最好的方法是维护一组请求ID并等待该集合变为零,但这似乎不够优雅。

1 个解决方案

#1


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.

通常,您希望使用我们称之为“Commander”的模式。基本上,你有一个有状态的演员(指挥官)负责启动和监控任务。然后,您可以在演员池中分配实际工作,并让他们在完成时向Commander报告。然后,指挥官可以通过计算工作池的#完成次数/大小来跟踪作业的进度。

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")

这样,工作人员可以在工作时独立监控和重新启动,但所有宝贵的任务级状态和信息都存在于Commander中(这称为“错误内核模式”)

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

您可以在Akka.NET可伸缩webcrawler演示中看到这样的示例。

#1


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.

通常,您希望使用我们称之为“Commander”的模式。基本上,你有一个有状态的演员(指挥官)负责启动和监控任务。然后,您可以在演员池中分配实际工作,并让他们在完成时向Commander报告。然后,指挥官可以通过计算工作池的#完成次数/大小来跟踪作业的进度。

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")

这样,工作人员可以在工作时独立监控和重新启动,但所有宝贵的任务级状态和信息都存在于Commander中(这称为“错误内核模式”)

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

您可以在Akka.NET可伸缩webcrawler演示中看到这样的示例。