Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should one use the Actor model?

When should the Actor Model be used?

It certainly doesn't guarantee deadlock-free environment.

Actor A can wait for a message from B while B waits for A.

Also, if an actor has to make sure its message was processed before moving on to its next task, it will have to send a message and wait for a "your message was processed" message instead of the straightforward blocking.

What's the power of the model?

like image 292
tilish Avatar asked Nov 28 '09 21:11

tilish


People also ask

Where can you use an actor model?

The actor model can be used as a framework for modeling, understanding, and reasoning about a wide range of concurrent systems. For example: Electronic mail (email) can be modeled as an actor system. Accounts are modeled as actors and email addresses as actor addresses.

What problems does the actor model solve?

An actor can send a message and continue without blocking. It can, therefore, do more work, send and receive messages. An important difference of passing messages instead of calling methods is that messages have no return value. By sending a message, an actor delegates work to another actor.

What is the actor model in computer science?

The actor model is a computer science concept that uses "actors" as the fundamental agents of computing. Actors take input, send output and perform functions. They can also create other actors.

What is actor model in context of a programming language?

The Actor model adopts the philosophy that everything is an actor. This is similar to the everything is an object philosophy used by some object-oriented programming languages, but differs in that object-oriented software is typically executed sequentially, while the Actor model is inherently concurrent.


1 Answers

Given some concurrency problem, what would you look for to decide whether to use actors or not?

First I would look to define the problem... is the primary motivation a speedup of a nested for loop or recursion? If so a simple task based approach or parallel loop approach will likely work well for you (rather than actors).

However if you have a more complex system that involves dependencies and coordinating shared state, then an actor approach can help. Specifically through use of actors and message passing semantics you can often avoid using explicit locks to protect shared state by actually making copies of that state (messages) and reacting to them.

You can do this quite easily with the classic synchronization problems like dining philosophers and the sleeping barbers problem. But you can also use the 'actor' to help with more modern patterns, i.e. your facade could be an actor, your model view and controller could also be actors that communicate with each other.

Another thing that I've observed is that actor semantics are learnable by most developers and 'safer' than their locked counterparts. This is because they raise the abstraction level and allow you to focus on coordinating access to that data rather than protecting all accesses to the data with locks. As an example, imagine that you have a simple class with a data member. If you choose to place a lock in that class to protect access to that data member then any methods on that class will need to ensure that they are accessing that data member under the lock. This becomes particularly problematic when others (or you) modify the class at a later date, they have to remember to use that lock.

On the other hand if that class becomes an actor and the data member becomes a buffer or port you communicate with via messages, you don't have to remember to take the lock because the semantics are built into the buffer and you will very explicitly know whether you are going to block on that based on the type of the buffer.

-Rick

like image 91
Rick Avatar answered Oct 05 '22 02:10

Rick