When to use different types of Akka mailboxes

I'm trying to understand when and where to use various Akka built-in mailboxes , as well as when you need your own. However, nowhere on this page does it explain what a " limited mailbox " is or how it behaves differently than an unlimited mailbox. In addition, this page classifies mailboxes as “blocking” and “non-blocking”. And although I have a strong idea of ​​what they mean by this (a message can be sent to the mailbox if the mailbox was not empty first), I'm not 100% sure that I understand this. Therefore, seeing that I have no idea what documents mean when they classify a mailbox as restricted or blocking, it is difficult for me to say when I should use each type.

In addition, it seems that Akka's default behavior clears the actor’s mailbox if that actor restarts. I would like to prevent this, but I’m not sure that the solution should use one of these built-in types of mailboxes (this page does not mention persistence of messages) or somehow use regular participants to achieve such a problem.

+5
source share
1 answer

Firstly, if an actor crashes and restarts, you only lose the current message that was being processed, and not the entire mailbox.

A limited mailbox has a limit on the number of messages that it can queue before it starts blocking the sender and will not allow the item if the queue does not drop while the sender tries to enable the item. If you have memory problems and can handle the potential loss of a message, you might want something similar. An unlimited mailbox has no capacity limitations, so there may be a memory problem if it is flooded.

Whether it is limited or not will affect whether it blocks or not. The lock is usually small for performance, and should be avoided if the situation does not require a limited mailbox. Therefore, the default mailbox is not limited; this will give much better performance than a limited counterpart.

A single-user unlimited mailbox is likely to be the fastest, as it is optimized only so that one consumer ever removes things from the queue. This means that you cannot use a dispatcher that allows an actor instance to steal items from another instance of the instance instance (duplication / theft of work), but if you do not care, then this mailbox may be the best choice for performance.

Priority-based mailboxes allow you to provide code that allows you to queue up depending on some attributes of the messages themselves. This allows you to prioritize messages yourself, and then they will move items with higher priority to the front of the queue, regardless of the usual FIFO rules.

+6
source