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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With