The Actor model

A specific variant of EDA is called the Actor model. Here, Actors refer to services that do the following:

  • Abstract the level, which indicates a primitive unit of computation
  • Encapsulate state

These Actors have mailboxes, where messages can be posted. The Actor sequentially takes each message from the mailbox and performs an action corresponding to the message. Each Actor has also some internal state that can affect the response to the messages.

Of course, there is more than one Actor and they communicate with each other asynchronously using messages. The overall system behavior is defined by these interactions and the processing by the Actors.

There are differences between this and the channel-goroutine semantics:

  • Each Actor is uniquely identified by its mailbox. So, when someone is sending a message, it is intended to be processed by a specific Actor. In a contract, a channel is a generic pipe. More than one goroutine can listen on the pipe.
  • The channels are in-memory. Mailboxes and generally cross-machine.

The actor model also follows the divide-and-conquer principle, and breaks up tasks until they are small enough to be handled by one sequential piece of code. The system can be reasoned about in terms of the messages exchanged. This is similar to OO programming, with the added powerful benefit that failure paths and actors can be different from the normal path. That way there is more freedom in handling unhappy paths. Another key advantage with other messaging systems is that both producers and consumers don't need to be alive at the same time, nor be operating at the same speed.

Generally, one actor assumes the role of a supervisor for a task and monitors the execution of the tasks in other actors. In case of risky or long-winded tasks, an Actor may spawn child Actors to do the sub-tasks and relegate itself to monitor the liveliness of the distributed computation among the children.

The Channel-Goroutine model is closer to the Communicating Sequential Processes (CSP), described by Hoare.

Erlang is the a famous example of languages that espouse this architecture style.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset