0

According to the Akka docs for 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.

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

So I ask: What's the point of this message and when would one ever use it, for any reason?!?

smeeb
  • 27,777
  • 57
  • 250
  • 447
  • 1
    It's one of the possibilities to stop actors. You may not want your actors to run forever instead do some task and stop. With the `PoisonPill` you ensure that the remaining messages get processed by the actor before stopping it. – hveiga Jun 04 '15 at 04:17

1 Answers1

2

We use a pattern called disposable actors:

  • 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.

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

shutty
  • 3,298
  • 16
  • 27
  • Thanks @shutty (+1) - ahh, this makes sense. So if I understand you correctly, you're saying its a good practice to clean up any actors that aren't currentlly being utilized, **yes**? This would make perfect sense. Thanks again! – smeeb Jun 04 '15 at 13:32
  • Actors are not threads/processes, they have different usage patterns. In some patterns starting/killing them is an acceptable behaviour, depending on the task. – shutty Jun 04 '15 at 13:37