I've seen it mentioned in several places in contexts like Erlang actor model, Groovy actors, Scala actor model etc. What does this refer to?
I think Wikipedia sums it up best:
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. [snip] The Actor model is about the semantics of message passing.
Some time ago I wrote this blog post that explains the basic concepts of the model and builds a basic implementation with JavaScript. From the post:
In the Actor Model, an actor is the foundation on which you build the structure of your application, it has internal state invisible to the outer world and interacts with other actors through asynchronous messages.
If this sounds to you a lot like Object-Oriented Programming (OOP), you are right. The Actor Model can be thought as OOP with special treatment to messages: they are delivered asynchronously and executed synchronously by the receiver.
Every actor is identified with a unique address by which you send messages to it. When a message is processed, it is matched against the current behavior of the actor; which is nothing more than a function that defines the actions to be taken in reaction to the message. In response to a message, an actor may:
- Create more actors.
- Send messages to other actors.
- Designate internal state to handle the next message.
Actor model main idea is to manage actors as a primitives for concurrent computation. Actor can send messages to other actors, receive and react to messages and spawn new actors.
The key idea here is to communicate through messages instead of sharing memory between different threads.
It's important to add that Actors are asynchronous and concurrent but they not guarantee message order or time limit as to when the message may be acted upon (hence atomic transactions cannot be split into Actors).
The usage of Actor model is suitable in the main two cases:
- When the can decompose your solution in a set of independent tasks.
- When you can decompose your solution in a set of tasks linked by a clear workflow.
Illustration:
© 2022 - 2024 — McMap. All rights reserved.