Background

Actor programming is one popular programming paradigm for distributed environments. Instead of using a typically programming language (e.g., Go) and communicating through RPC (e.g., gRPC), one can use an actor program language (e.g., Erlang) or an actor library (e.g., Ray) to write distributed programs at a higher level. As an analogy, Go+gRPC is kind of like writing assembly, where actor programming is kind of like Object-Oriented programming for distributed environments.

You can think of Actor is Class in OO programming. But when OO was designed, it didn't take into account the possibility of multi-threading and distributed environments. For example, what would happen if both Object B (thread 1) and Object C (thread 2) invoke ObjectA.method1 (thread 3)? The Actor programming model is designed with concurrent access and distributed setting as first-class citizen. Each actor can communicate with the others ONLY by sending messages (thereby no race condition). Furthermore, since everything is an actor (just like everything is an object in OO programming) and communicated by sending messages, an actor can be located and moved to different physical places easily (e.g,. local server, to the cloud).

In this lab, we will implement a simple distributed chatting application base on Actor model with Ray, a distributed execution framework.

We will implement 2 types of Actor, UserActor and ChatRoomActor.

One UserActor is created per user. It is responsible to send/receive chats to/from the ChatRoomActor. ChatRoomActor broadcasts the chats it received to all UserActors.

In this lab, we will demonstrate how good Actor programming fits a distributed environment, especially the cloud environment where it can automatically scale out when the workload (e.g., the number of users in a chatroom) increases.

Last updated