tarant icon indicating copy to clipboard operation
tarant copied to clipboard

[Question] How to stop an Actor?

Open fermuch opened this issue 3 years ago • 4 comments

Suppose I have a system where I spawn an actor to manage each item in a list. Once the item is removed from the list, how can I stop the Actor?

  • tarant version: 3.1.1

fermuch avatar Feb 04 '22 19:02 fermuch

any answer ?

gpicron avatar Jan 18 '23 18:01 gpicron

Sadly not. I had to create a special message requesting the Actor to "die". Once the actor receives that message, it kills itself.

I would love to have an official way to kill actors, tho'.

fermuch avatar Jan 18 '23 18:01 fermuch

Hi @fermuch,

apologies for the late response.

You are totally right, there is no specific way to stop a single actor right now, as there would be different strategies to do it and we (@kanekotic and I) were designing which would be the best way. Can I ask you what would you consider the most efficient way to stop an actor to gather your feedback?

Questions we were trying to answer:

  • What happens with the mailbox when an actor is stopped? Should we process pending messages? What happens when a pending message is then failing?
  • What happens when an actor is stopping and receives new messages? Should they go to a dead letter? Or notify the sender that the actor does not exist anymore?

Thanks a lot and sorry for the late response.

kmruiz avatar Jan 21 '23 19:01 kmruiz

What happens with the mailbox when an actor is stopped? Should we process pending messages? What happens when a pending message is then failing?

I think there should be two ways to stopping an actor: request and force.

REQUESTING

  • The actor should decide if it must stop (a callback with a boolean response?)
  • The actor should stop getting new messages (trying to append to a stopped actor should raise an error).
  • The actor should process every message it had right until the stop message.
  • A last message should be sent, so the actor can clean its resources.

FORCING

  • The actor is stopped immediately.
  • All pending messages in the mailbox are discarded.

Note: in both cases, the requester (sender) of the stop message should have the possibility to wait for the actor to be fully stopped, so a new actor can be spawned with the same details.


By separating into these two, I think all use cases are solved. By requesting, you give the actor time to process its pending messages. And, if you need, you can kill it immediately.

fermuch avatar Jan 23 '23 14:01 fermuch