How to prevent actor mailbox expansion in Scala?

As you know, mailboxes Scala actors has no size limit. Thus, if an actor reads messages from his mailbox more slowly than others, sends messages to this mailbox , then this ultimately creates a memory leak.

How can we be sure that this is not so? Should we limit the size of the mailbox ? What are the best methods to prevent mailbox growth?

+6
source share
1 answer

Instead of having a push strategy where manufacturers send messages directly to consumers, you can use a pull strategy where consumers request messages from manufacturers.

To be sure that the answer is almost instantaneous, manufacturers can produce a limited amount of data in advance. When they receive a request, they first send one of the preformed data, then generate a new one.

You can also use Akka actors who provide a limited inbox.

+4
source

Source: https://habr.com/ru/post/892837/


All Articles