golang

Akka Actors & Go channels made simple

The objective of this post is to understand the differences between the Akka Actors and Go Channels and how they are related to each other.

Both Akka Actors and Go Channels describe independent ways to communicate independent process via message passing.

Akka Actors
Akka actors implement the Actor model (Hewitt, 1973).
In the Actor model, the communication between two independent processes is completely decoupled. Message delivery is not confirmed to the sender and may take an arbitrary amount of time. The result of this is that Actors will be more independent from each other as they can choose when to handle a message based on internal state. The disadvantage is that Actors require to buffer messages and a mailbox of theoretically unbounded size.

Akka_logo_transparent

The advantage of Akka Actors is that because the message passing is decoupled, it becomes trivial to run processes in different network nodes. It allows the receiver to be offline and not to receive the message without affecting the sender as the sender wont wait for getting a reply.

actor-model (1)

Go Channels
Go Channels implements the paper Communicating sequential processes (Hoare, 1978).
In Go Channels, a message exchange is synchronous with a “touch point” of the execution. Processes hand over messages one to another.

The benefit is that Channels do not need to buffer messages, a block of code will react when a message arrives on the channel. Concurrency then become transparent to the programmer.
gophereartrumpet

Go programs usually deal with different checks for messages not to block the program from making progress. Channels are really useful for processing concurrent sequential jobs in a controlled environment (e.g. Single VM with multiple cores), enabling the developer to build a correct program, scalable and with a parallel design.

Core 1
gophereartrumpet

Core 2
gophereartrumpet

Conclusion
While Akka Actors are more useful to use in a distributed computing with fault tolerance because of the capability to decouple producer and consumer, consequently is not possible to write data-driven synchronised structures.
It can be applied to build Trading and Gaming systems but not applicable for lock-step data-driven flow control of robotics.

Go gets the best of both approaches and is more general than the Actor model. In Go you communicate your processes by messaging over a channel inside your controlled environment. And If you want to use Go channels in a distributed environment, checkout Go Circuit framework.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s