Akka演员的杀死/重启行为

编程入门 行业动态 更新时间:2024-10-09 19:15:50
本文介绍了Akka演员的杀死/重启行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对Akka中看到的行为感到困惑。简而言之,我有一组演员进行科学计算(恒星形成模拟)。他们有一些状态。当发生错误而使一个或多个进入无效状态时,我想重新启动整个程序集以重新开始。如果单个calc(在整个集合中)花费的时间太长(也无法提前预测它可以运行多长时间),我也想这样做。

I am confused by behavior I am seeing in Akka. Briefly, I have a set of actors performing scientific calculations (star formation simulation). They have some state. When an error occurs such that one or more enter an invalid state, I want to restart the whole set to start over. I also want to do this if a single calc (over the entire set) takes too long (there is no way to predict in advance how long it may run).

因此,在树的底部有一组模拟角色,然后是它们上方的控制器(可以通过路由器创建它们,并通过该路由器发送消息)。上面还有一个Director级别,可以在不同的计算机上创建Director并从它们中收集所有结果。

So, there is the set of Simulation actors at the bottom of the tree, then a Director above them (that creates them via a Router, and sends them messages via that Router as well). There is one more Director level above that to create Directors on different machines and collect results from them all.

我通过使用Akka Scheduler创建一个超时实例来处理超时情况-time timeout事件,在本地控制器中,模拟开始时。当导演获得此事件时,如果其所有模拟演员都没有完成,它将执行以下操作:

I handle the timeout case by using the Akka Scheduler to create a one-time timeout event, in the local Director, when the simulation is started. When the Director gets this event, if all its Simulation actors have not finished, it does this:

children ! Broadcast(Kill)

其中的孩子是拥有/创建它们的路由器-这向所有人发送了Kill

where children is the Router that owns/created them - this sends a Kill to all the children (SimulActors).

我认为将会发生的事情是所有的儿童演员都会重新开始。但是,永远不会调用其preRestart()挂钩方法。我看到收到了Kill消息,仅此而已。

What I thought would occur is that all the child actors would be restarted. However, their preRestart() hook method is never called. I see the Kill message received, but that's it.

我肯定在这里缺少一些基本信息。我已经阅读了有关此主题的Akka文档,不得不说我发现它们不够清晰(尤其是有关主管的页面)。我真的很希望对Kill / restart过程进行彻底的解释,或者仅提供一些其他参考(Google并不是很有帮助)。

I must be missing something fundamental here. I have read the Akka docs on this topic and I have to say I find them less than clear (especially the page on Supervisors). I would really appreciate either a thorough explanation of the Kill/restart process, or just some other references (Google wasn't very helpful).

推荐答案

注意

Note

如果路由器的子节点终止,路由器将不会自动产生一个新的子节点。如果路由器的所有子级都终止了 ,路由器将自行终止。

If the child of a router terminates, the router will not automatically spawn a new child. In the event that all children of a router have terminated the router will terminate itself.

摘录自 akka文档。

更多推荐

Akka演员的杀死/重启行为

本文发布于:2023-11-25 06:05:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重启   演员   Akka

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!