Mailbox
In the GoAkt actor framework, the mailbox is a fundamental component that functions as the queue for messages sent to an actor. Every actor has its own mailbox that collects incoming messages until the actor is ready to process them.
This design is central to the actor model: rather than sharing state or locking resources, actors communicate solely by exchanging messages via their mailboxes, ensuring isolation and concurrency while maintaining a sequential processing order.
The mailbox in GoAkt plays a crucial role in decoupling message senders and receivers by buffering messages until the recipient actor is ready to process them. It not only ensures that messages are handled in a controlled, sequential manner but also integrates with the actor’s supervision and lifecycle management.
By isolating each actor’s message flow, the mailbox enables robust fault tolerance and scalability, allowing the system to support both local and distributed messaging patterns seamlessly while optimising resource usage and throughput.
One can implement a custom mailbox. See Mailbox.
GoAkt comes with the following mailboxes built-in:
UnboundedMailbox
: this is the default mailbox. It is implemented using the lock-free Multi-Producer-Single-Consumer Queue.BoundedMailbox
: this is a thread-safe mailbox implemented using the Ring-Buffer Queue. When the mailbox is full any new message is sent to the deadletter queue. Setting a reasonable capacity for the queue can enhance throughput.UnboundedPriorityMailbox
: this is thread-safe mailbox using the standard library container/heap. At the moment the performance of is this mailbox is not comparable to the two other built-in mailboxes.
Last updated