upvote
Thank you.

This is the kind of knowledge and wisdom I come to HN for. Seriously.

The systems from the 60s and 70s and 80s were designed by brilliant people.

What is old is new again.

reply
COBOL systems and the related hardware was excellent. I remember our company running Unisys mainframes way back in the days, and they were absolute beasts. I think we need a modern equivalent. COBOL was truly an unpleasant language (to me) and yet pretty elegant in many ways.
reply
COBOL did not implement the actor model. There are several devils in the details here which distinguish the actor model from the similarities to COBOL systems.

One of the biggest differences is that in actor systems, there's no intermediate queue-like channel that messages are sent to. Messages are sent directly between actors, peer-to-peer. Each actor manages its own private message queue. Similarly, each actor has logically isolated state, so actors can't affect each other except by sending messages.

To achieve the kind of queue-based concurrency you mentioned, the idiomatic actor pattern is to spawn a new actor per request. In the Erlang BEAM VM for example, an actor (Erlang calls them processes) typically spawns within a few hundred nanoseconds.

If you want a shared queue, you can implement an actor to serve that purpose, and there are standard implementations of this. This is kind of the opposite of what COBOL does. The actor and its peer to peer communication are the primitives, and things like shared queues are implemented at the application level. This alone means COBOL does not follow the actor model.

Another big difference is how OS process and thread management are used. No COBOL system ever implemented what Erlang does, which is a single, reliable OS process that manages multiple strongly isolated actors with preemptive scheduling.

CICS came the closest in its early versions, running multiple tasks/units in a single address space on a single thread. But it used cooperative multitasking, not preemptive, and isolation between tasks was fragile - it was quite common for unhandled exceptions or memory overwrites to bring down the the entire CICS address space, terminating all active users. The logical isolation of actors solves for the latter issue. In Erlang, each actor has its own garbage-collected memory pool, and actors can crash without affecting the rest of the system.

The way that was solved in the COBOL world was to move to relying on OS-level concurrency. Tandem NonStop, designed for high availability, was a good example of this. In fact, Erlang inventor Joe Armstrong was influenced by it, but he took advantage of the actor model to implement a much more reliable version of what early CICS systems had - a single OS process running multiple tasks, but with preemptive scheduling and strong task isolation.

You don't have to squint too hard to see resemblances between COBOL and the actor model, but key features of actors, including peer-to-peer task messaging and either (1) strong task isolation or (2) no dependence on OS-level concurrency mechanisms like processes or threads, were never implemented in COBOL systems (afaik).

Actor model systems like Erlang allow for the possibility of running without an OS, because they already handle their own process scheduling, memory isolation, and IPC, so all that's left is drivers, networking, and a bootloader.

Several projects have done this, and the OP article is describing a non-Erlang system in that vein.

Examples of Erlang/BEAM as OS include LING (runs directly on the Xen hypervisor), GRiSP (runs on bare metal embedded systems), AtomVM (for microcontrollers with only kilobytes of RAM), and Nerves (runs on a bare minimum Linux kernel with BEAM as PID 1, to take advantage of hardware drivers.)

reply
> 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.

reply
I think you and the parent are saying the same thing. The previous sentence to the one you quoted says:

> in actor systems, there's no intermediate queue-like channel that messages are sent to.

There are essentially two message passing models:

1. Multiple writer/single reader

2. Multiple writer/multiple reader

Where multiple/single means the number of actors/processes[/whatever] that can read or write to a queue.

Erlang and the Actor model are examples of the former. Multiple Actors can write to a given queue but only one Actor can read from it. From the writer's perspective, the queue is part of the reading Actor; the abstraction boundary encompasses the queue. Strictly speaking, the writer doesn't even know a queue exists: it just has a porthole it can push messages at.

Internally the Actor comprises 3 things: (1) the queue, (2) the read loop, and (3) the actions that get called in the read loop based on the received message. None of that is visible outside the Actor though. If you draw a diagram of an Actor system, it only shows Actors and the messages sent among them. Queues are hidden at that level.

Contrast that with the multiple reader/multiple writer scenario. This is the model used in service bus middleware like RabbitMQ. In this case the queues are external to the readers and writers. A system-level diagram would show the queues as first-class entities, alongside the components reading and writing to them.

reply
I completely agree with what you say.

As I have already said in another comment, I assume that the poster to which I have replied meant to say that the COBOL queues are many-to-many message queues, which are distinguished from many-to-one message queues exactly as you describe.

However the original comment was not clear, because the difference in behavior in comparison with actors is not given by the existence or non-existence of queues, which must always exist for message passing, but in the important differences both in implementation techniques and in their behavior, between many-to-one queues and many-to-many queues.

reply
I explicitly mentioned that each actor manages it's own queue, I didn't say anything about the non-existence of queues.

The distinction is between the use of queues shared between tasks and queues that are owned, and only readable by, each individual task (actor).

Another point about all this is that actors aren't just a concurrency mechanism that you can use or not as you see fit. They're a fundamental unit out of which entire applications are built. There are no function calls between actors, only message passing. This provides useful global concurrency safety properties that other systems can't match unless they essentially reimplement some similar model throughout the system.

What I'm getting at here is it's not just the properties of the individual queues that matter, but how the model is applied and enforced system-wide.

reply
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.

reply
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.

reply
I assume that in the COBOL case by "shared message queue" you mean "many-to-many" message queue.

I have written COBOL programs in the very distant past, but they were not concurrent programs, so I do not know how COBOL queues behave, so you are probably right.

But the input queues of actors must also be shared, i.e. they must be "many-to-one" message queues, because there are many other actors which can send messages to an actor.

There are 3 kinds of shared message queues: many-to-one, one-to-many and many-to-many. Whenever the message queues may be used by multiple threads, which is always on modern CPUs, the 3 kinds of shared message queues must use certain methods to allow concurrent accesses, which are different for the 3 kinds of queues.

Obviously, many-to-many queues have the most complex implementation, while many-to-one queues are simpler, but they must still use atomic instructions in the right way, to avoid data corruption. Only the one-to-one message queues do not need atomic instructions, but only store-release and load-acquire instructions.

reply
By shared queue I mean that the queue doesn't belong to any single task or actor.

Each actor owns its own queue, and is the only reader. This makes it a many-to-one queue.

> Whenever the message queues may be used by multiple threads, which is always on modern CPUs, the 3 kinds of shared message queues must use certain methods to allow concurrent accesses, which are different for the 3 kinds of queues.

This is exactly what actor systems like Erlang avoid. The Erlang VM handles preemptive multitasking for the actors it manages, without using OS threads. This eliminates a lot of concurrency issues, and is a big part of why Erlang systems have such a reputation for reliability.

You can think of it like a green thread system where each thread has its own private message queue.

> but they must still use atomic instructions in the right way, to avoid data corruption.

This is only an issue because the message queues you're talking about are implemented separately from the OS, so there are no guarantees about concurrency behavior. This is exactly what the actor model solves for.

reply
OK, with your definition for "shared queue" what you said initially was correct, but by "shared data structure" I understand that the access to it is shared between multiple active entities, even if the data structure is owned by only one of those entities, hence the miscommunication.

In general, in programs it does not matter much where you put artificial borders of ownership between entities, but whether the access to a resource is shared or exclusive has a crucial impact on the required code.

If threads are not visible to the programmer who writes the code for an actor, there are 2 cases. The first is when threads really do not exist, in which case the VM is single-threaded and executed on a single core of a modern CPU, so the achievable performance is modest, but there is no need for handling concurrency.

The second case is when the VM is in fact multi-threaded, which, as you say, must be the case for Erlang, but it manages the scheduling of the threads itself, and the allocation of actors to threads, in a manner transparent for the programmer.

In this case the VM must include code for managing concurrent accesses from multiple hardware threads to the message queues, so they still are shared-access queues, even if their implementation is provided by the VM.

reply
deleted
reply
Is there a reason why couldn't use both? External queues are useful in that I don't have to care about "who" the recipient is, just the job that I expect will be done by depositing something to a queue. "Who" becomes a consumer problem that the producer doesn't have to involve themselves with.
reply
deleted
reply
> I don't have to care about "who" the recipient is, just the job that I expect will be done by depositing something to a queue.

I mentioned that in my first comment. In actor systems, the idiomatic model is just to spawn a new actor for each job.

But if you want a multi-reader message queue, you can implement an actor that provides that, and there are standard implementations of this.

Actors are the primitive mechanism on which other concurrency mechanism can be built, without all the problems of traditional threads.

reply
Message queues never went away but were certainly set aside during the personal computer revolution. One thing that changed is that users now expect timely if not immediate results; Actor models like Erlang's bring a notion of realtime constraints that AFAIK didn't exist in previous batch processing architectures.
reply
So Factorio.
reply