Akka PoisonPill用例 [英] Use case for Akka PoisonPill

查看:100
本文介绍了Akka PoisonPill用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据PoisonPill的Akka文档:

您还可以向演员发送akka.actor.PoisonPill消息,该消息将在处理该消息时停止该演员. PoisonPill被列为普通邮件,将在邮箱中已排队的邮件之后进行处理.

You can also send an actor the akka.actor.PoisonPill message, which will stop the actor when the message is processed. PoisonPill is enqueued as ordinary messages and will be handled after messages that were already queued in the mailbox.

尽管对于Akka Guru来说,这种功能的有用性/实用性对于新手来说是显而易见的,但这听起来完全是无用/鲁ck/危险的.

Although the usefulness/utility of such a feature may be obvious to an Akka Guru, to a newcomer, this sounds completely useless/reckless/dangerous.

所以我问:此消息的目的是什么?出于任何原因何时会使用它?!?

推荐答案

我们使用称为disposable actors的模式:

  • 为每个申请请求创建一个新的临时参与者.
  • 该参与者可能会创建其他参与者来执行与请求相关的某些工作.
  • 处理后的结果发送回客户端.
  • 与此请求有关的所有临时演员都被杀死.那就是使用PoisonPill的地方.
  • A new temporary actor is created for each application request.
  • This actor may create some other actors to do some work related to the request.
  • Processed result is sent back to client.
  • All temporary actors related to this request are killed. That's the place where PoisonPill is used.

创建一个actor意味着非常低的开销(大约300个字节的RAM),因此这是一个很好的实践.

Creating an actor implies a very low overhead (about 300 bytes of RAM), so it's quite a good practise.

这篇关于Akka PoisonPill用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆