简体   繁体   English

演员模型中的演员的生命游戏

[英]Lifecyle of an actor in actor model

I'm a newbie to actor model. 我是演员模特的新手。 Could anyone please explain the lifecycle of an actor in actor model? 任何人都可以在演员模型中解释一个演员的生命周期吗? I've been looking for the answer in the documentation, but I couldn't find anything satisfactory. 我一直在寻找文档中的答案,但我找不到任何令人满意的东西。

I'm interested in what an actor does after it completes the onReceive() method - is it still alive or is it dead? 我对演员在完成onReceive()方法后所做的事情感兴趣 - 它还活着还是死了? Can we control its lifetime to say "don't die, wait there for the next message"? 我们可以控制它的生命周期来说“不要死,等待下一条消息”吗? For example, with a round-robin router, if I set it to have 5 actors - would it always distribute the work across the same 5 actors? 例如,使用循环路由器,如果我将其设置为有5个演员 - 它是否总是将作品分配到相同的 5个演员? Or actors are destroyed and created anytime there is a message, but the maximum limit is always 5. 或者演员在有消息时被销毁并创建,但最大限制始终为5。

Thanks! 谢谢!

The Actor is always alive unless you explicitly "kill" it (or it crashes somehow). 除非你明确地“杀死”它(或者它以某种方式崩溃),否则Actor总是活着的。 When it receives a message, it will "use" a thread, process the message, then go back to an "idle" state. 当它收到消息时,它将“使用”一个线程,处理该消息,然后返回“空闲”状态。 When it receives another message, it becomes "active" again. 当它收到另一条消息时,它再次变为“活动”。

In the case of a round-robin router with 5 Actor s, it is the same 5 Actor s - the router does not create new ones each time a message is sent to the router. 对于具有5个Actor的循环路由器,它是相同的5个Actor - 每次向路由器发送消息时路由器都不会创建新的。

The Actor model follows an "isolated mutability" (concurrency) model - it encapsulates state only to itself - other Actor s are not able to touch this state directly, they can only interact with it via message passing. Actor模型遵循“孤立可变性”(并发)模型 - 它仅将状态封装到自身 - 其他Actor无法直接触及此状态,它们只能通过消息传递与之交互。 The Actor s must be "alive" in order to keep the state. 为了保持状态, Actor必须“活着”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM