actor VS. channel

Actor Model

An actor is the primitive unit of computation. It receives and sends messages and processes them. Since actor communicates with messages and does NOT have shared states, actor is completely isolated, which means it can be the basis of a distributed system.

Actors are like ants: in actor model, everything is an actor and they talk with messages where unique addresses (to identify who i am) are required.

Messages are sent asynchronously but Actor itself processes message sequentially. So first actor should have a mailbox for storing messages and second if multiple messages should be handled concurrently, multiple actors should be created.

Actor can maintain a private state to make decisions like FSM(finite sate machine).

When actor receives a message, it can decide what to do from following 3 staffs:

  • spawn more actors
  • send message to other actors
  • how to deal with next message (e.g. accept / reject)

Actor is fault-tolerant. It follows the famous philosophy “let it crash” (Erlang). When an actor crashes, its supervisor (another actor) will be notified and decides what to do (e.g. reset this crashed actor to its initial state). Actors are completely isolated, so one crash will not affect others.

More on wiki.

CSP

Communicating sequential processes describes another way of interaction in concurrent systems, which focuses on “interaction” (message passing). In CSP, messages are passing via channels. A channel like a meeting room, both processes enter in this room and exchanges their messages. So channel itself performs as a locker for shared state to eliminate shared memory between processes. “Do not communicate by sharing memory; instead, share memory by communicating."

More on wiki.

Akka actors VS. Go channel

Actor mailbox is like a infinite buffered channel, so no blocking during message exchange (fully asynchronously). Un-buffered go channels and fixed size buffered channels have blocking states (e.g. buffer is empty / full).

Actor is non-blocking, so NO deadlock will happen, but channel can (e.g. use -race when running tests).

Actor can NOT refuse to communicate, but goroutine can choose through select.

Actor can work on distributed systems but goroutine works within a single machine.

More on Quora

Future

proto-actor

comments powered by Disqus