Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent actor mailbox growing in Scala?

Tags:

scala

actor

As for as I know, the mailboxes of Scala actors have no size limit. So, if an actor reads messages from its mailbox slower than others send messages to that mailbox, then it eventually creates a memory leak.

How can we make sure that it not does happen? Should we limit the mailbox size anyway ? What are the best practices to prevent the mailbox growing?

like image 659
Michael Avatar asked Jul 15 '11 14:07

Michael


1 Answers

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

To be sure that the reply is almost instantaneous, producers can produce a limited number of data in advance. When they receive a request, first they send one of the pregenerated data, then they generate a new one.

You could also use Akka actors, which provide bounded mailbox.

like image 199
paradigmatic Avatar answered Nov 15 '22 04:11

paradigmatic