logoalt Hacker News

adrian_b • today at 2:18 PM • 2 replies • view on HN

> Messages are sent directly between actors

Such a thing cannot exist whenever more than 1 actor can be executed simultaneously.

An actor may have a single input queue, and all other actors can send messages to that unique input queue.

In this case, because there is a 1-to-1 mapping between input queues and actors you could identify the input queues with the actors.

But inside the code implementing the actor, you must have a loop that extracts messages from the input queue, so you must be aware that the input queue exists and it is not the same thing as the actor.

If you had a bad actor implementation without a unique input queue, than you would need something like a separate mailbox for every other actor, where the other actors would deposit messages and each actor would have to poll continuously all such mailboxes, to catch the arrival of any messages, which would be very inefficient.

"Spawning a new actor per request" just means that the implementation of the actor is split into 2 parts, the loop that extracts messages from its input queue and a function that is invoked upon the arrival of a new message, having the message as argument.

Such a splitting makes sense, because the loop handling the input queue could be the same for all actors (but acting on different input queues), with only the function that is invoked for a message containing the part that is different for each actor.


Replies

eproxus • today at 2:25 PM

That's exactly how Erlang works, except it doesn't poll continuously, it has a receive statement that blocks and waits for messages. The reason this can be made efficient is because the actor itself is not polling, the scheduler (the actual thread executing the actor) knows that the actor is waiting and executes other things while waiting for messages. It is much more reactive.

I'm guessing an OS built on the BEAM or a similar model would take a similar approach, where code executed by actors is actually run in schedulers, that can multiplex them and make the message passing efficient because they know what happens in the system.

antonvs • today at 2:22 PM

The very next sentence after the one you quoted was, "Each actor manages its own private message queue." That covers everything you're saying, which is basically describing how actors are implemented.

The point is that it's not a shared message queue as in the COBOL case, or most enterprise queuing systems. An actor is a self-contained, isolated object with its own message handling and state, and it executes concurrently with all other actors.

As such, this is not quite correct:

> you must be aware that the input queue exists and it is not the same thing as the actor.

The term "actor" refers to the bundle of state, behavior (handler loop), and message queue.

You certainly must be aware of the existence of the queue though, but since you have to write a message handler loop for each actor, it would be difficult not to be.

➕ show 2 replies