OLd(er) person here. If you want look at earliest Actor models then look at COBOL programs from 70s that used queues (it's part of COBOL standard).
Programs would read from specific queues for input data, transform that data and then write some to data stores and some to downstream queues. This created DAG environments for data and transaction flow.
Scaling in these environments was done by monitoring load and back pressure in the queues and firing multiple readers. Transaction Processing Monitors like VRX and CICS managed this at OS level and the COBOL programs managed at unit level.
COncurrency was running multiple units reading from same queue to do same function.
this is one reason why a ton of these older systems still running.
DAG workflow, automatic balancing, queue based actor models with transactions.
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.
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.
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.)
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.
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.
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.
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.
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.
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.
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.
I am a bit skeptical of the non-blocking claims, as actor systems usually make several tradeoffs, that handle the classical 'blocking' issue differently (by which I mean I read a 100MB file synchronously on the UI thread, and the program appears to freeze).
Classical actor systems at their simplest only support sending one-way messages, and these are indeed non-blocking.
But they are not very powerful either. People usually introduce the 'remote procedure call' on top of this, by which actor A can call actor B and expect B to respond. You can do this with corellation IDs for example.
The question is what does actor A do while waiting for 'B'? In the simplest form it continues to serve other messages, making the actor reentrant, which can create incredibly surprising scenarios as code executes while you don't expect to changing actor fields in unexpected ways.
Or you can have actor A wait to finish processing the call to 'B'. But now you have blocking, as 'B' can prevent anyone talking to 'A' from making progress.
Or you can do something computer-sciencey, like doing transactions and specifying the conditions under which A can server multiple ongoing requests, and how to reconcile them.
I'm sure there are many options, but actors have been a cool idea for a while, and many event driven paradigms borrow from it, that are incredibly widespread to the point that I'm sure most people have programmed in a system before, and have experienced 'callback hell'.
> In the simplest form it continues to serve other messages, making the actor reentrant, which can create incredibly surprising scenarios as code executes while you don't expect to changing actor fields in unexpected ways.
That's probably why GUI programming is so hard and every GUI sucks.
Anything that happens outside RAM requires you to respond to every possible input in the middle of any possible operation
The first one is a rare gem: a conversation among the creators of the foundational concurrency models. Carl Hewitt (Actor Model), Tony Hoare (CSP, Communicating Sequential Processes, which inspired Go's goroutines and channels), and Joe Armstrong (co-creator Erlang).
You can extend this with "linear type" message passing where you transfer ownership of an object. That avoids physically copying memory and the sender loses write access to enforce the one writer at a time constraint.
It means a pipeline of actors can process a file with the same memory usage and only a tiny bit more CPU than a monolithic program, but it stays isolated and hot swappable.
This might already be implemented in the OS but the post doesn't mention it.
The BEAM on Erlang sort of does this with its global binary heap so you can have multiple readers. The binary must be larger than 64 bytes so it's stored on the global binary heap instead of copied onto process heaps. Its not really linear type though as there is no transfer since all data is immutable.
Implementing linear messages at the OS level is a cool idea. I’ve loved building linear types in my language, they’re super nice to work with and give you some good tooling and compiler options. I’ll bet an OS could do a lot with the idea.
The headline advertises 'no threads', but in the article, it mentions all actor methods are non-blocking, and async. Not blocking what?
The whole purpose of async is to have a message pump thread, and allow concurrency by yielding the timeslice. It's also needed because many async runtimes interact with APIs that need to be called from a single main OS thread.
I would presume an OS designed to be all actors, all the way down would do away with the need for a message pump thread, and single threaded APIs. In this case, cross-actor calls might as well be sync, with required preemption handled on the OS level.
Having to pay the async overhead over 100% of cross-actor calls is very expensive.
There is an extra step after "you ask the OS to do something on your behalf and ask it when it’s done".
That is "you ask the OS to do something on your behalf and you do not have to check when it is done", because you have a unique queue where you receive notifications about everything that is of interest for you, including the completions of I/O activities that you have requested previously.
"You ask the OS to do something on your behalf and ask it when it’s done" was an ancient method to perform asynchronous I/O, which survived in many operating systems much more years than it should. Continuing to use such a method today is a mistake.
The best method for asynchronous I/O is with a unique input queue, like in the Linux io_uring. The second best method, because it can be used to implement a unique input queue, is with what in DEC RSX-11M was called "Asynchronous System Trap Service Routine", i.e. a callback function to be invoked upon I/O completion, which was inherited from DEC RSX-11M into DEC VMS, from where it was inherited into Microsoft Windows NT, and then in 1994 MS Windows NT 3.5 introduced the "I/O Completion Ports", which was AFAIK the first improvement in asynchronous I/O handling after what DEC RSX-11M did 20 years earlier, in 1974 (which was again the first improvement over what IBM PL/I already had in 1964, when it had the equivalent of WaitForMultipleEvents, but in a more powerful variant than in Windows NT).
I/O uring is built upon this, with it i can serve 155 http responses per syscall, whereas with epoll i can serve 0,2.
Having your OS do the batching for you can make it twice as fast.
My new http implementation went from 3 million responses per second per thread to 6 million, just from replacing epoll and non blocking sockets with liburing and batching.
> The headline advertises 'no threads', but in the article, it mentions all actor methods are non-blocking, and async. Not blocking what?
I think the very brief answer to that is: "Processes." as in the general concept of communicating processes. How those are actually implemented on another layer depends on the platform. You can also run an actor system on a machine, that can only do one thing at a time, using a single CPU core. The work the process does is not blocking, but the platform might not have the capability to do more than one thing at a time. But this is different from work being inherently sequential.
I think this taxonomy is not good. It’s comparing apples to oranges, or apples to fruit sugars or something.
Threads are not a programming paradigm or style, any more than a CPU is a programming paradigm or style. They’re a tool, an existential piece of the landscape which can be used to perform paradigms/styles. Like CPUs, they do have affinity for certain use cases, but the car is not the road trip.
If threads don’t share state, they are effectively the same as processes. The whole purpose of having threads in addition to processes is to share state. If you don’t share state, you don’t need threads. That’s what the blog post means by “an OS with no threads”.
It’s pre-coffee, and I totally disagree “threads are not a programming paradigm”. But the best way to do that is to say that the car IS the road trip and it’s a fundamentally different thing if you use a train.
Threads are an OS level concept introduced by a kernel, e.g. the Linux kernel. If you do not have an OS at all, you do not have threads (lets ignore hardware threading for the sake of the argument). You just have the core itself be occupied by the actor scheduler, but no thread scheduler.
Blocking is not a threading or even OS concept. Blocking is a CPU core and programming language concept derived from sequential processing. Blocking means that instructions behind the block are not being executed while the block is in progress.
In the actor model, sending a message must never prevent the execution of instructions that follow after sending the message. The continued execution of further instructions must be guaranteed until the actor has processed the message. Responses must be received through the actor's mailbox.
Since blocking as an absolute concept may not make much sense, because all sequential processes (e.g. execution of an instruction) are blocking temporarily, the author decided instead to define a time bound, so if mail box processing takes too long, simply because the algorithm is CPU intensive, the author considers it blocked as well and schedules the next actor.
Edit: I guess the confusion comes from the fact that Rust's async facility automatically converts the code into a state machine that is compatible with actor execution semantics, but technically violates the spirit of actors.
I look at it differntly. There is no fundamental difference between async paradigm and threads. The only difference is where the call stack is.
It just happens that in threads, there is this magical place called stack that you can SUPER fast allocate memory for new function frame. If you have a complex program that uses many deep very deep calls to functions withing functions within functions, you dont need to deal with register allocation or even "local stack frame" for local variables allocations. You just zip in and zip out of the "thread" stack all the time, millions times per second.
The disadvantage is that if for whatever reason a deeply nested thing needs to do _something_, typically I/O, then there is no easy way to yield and allow someone else to use ALU. One option is to change stack register to some other stack and continue other stream of compute. This done by OS is called a context switch.
However, for certain problems, there is an alternative - async. In async the "stack" for local variables is more explicit, very often on the heap, and is managed differently. Every time you are calling a nested function it also needs to store the local variables somewhere, so either you emulate stack somehow (in which case this is not much differnet than normal thread) or allocate the nested function local variables space using memory allocator on heap or special memory.
This is great beause it allows you to reduce the cost of a context switch - now you don't need to change the stack pointer and save context, becasue context is by definition saved in the async block. Asnc also allows you to NOT overcommit on stack size for some future deep deep nested fucntion calls that might never happen. In async you know exactly where you can yield and can plan for it.
However it's not like these two models are fundamentally different. It's the same problem of "where the local variables live" and "how to allocate this memory". We have far bigger problem - due to historical reasons "blocking" is a thing, but this is is only because we made mistakes designing operating systems (I'm looking at you fsync, open, close, or even bpf() syscalls).
I do think they’re fundamentally different, for two reasons:
1. The decision of when to switch routines is more consequential than the cost of stack or context switching. Letting the OS decide results in behavior that is consistently fair for all programs, caveat scheduler bugs. Letting user code decide results in behavior that is only as fair as a given program. Writing code in the latter environment entails wrestling with the reality that it may not run to completion unless other code in the environment lets it. That applies in async programming to a much wider range of situations than kill signals/aborts, which are the only even slightly analogous things in threaded programming.
2. Async is a subset of threaded programming (it has a hardware stack, and can call typical context-switchful code if it wants to block).
On ancient single-core single-thread CPUs, threads were indeed a concept introduced by the operating system, and the use of threads was completely optional.
On modern CPUs, which have many hardware threads, the operating system and the user programs must handle at least the number of hardware threads, e.g. 32 threads on an AMD 9950X.
Implementing more threads than the hardware threads is optional, but the hardware threads must have their own states and stacks and if they exchange messages the inter-thread messages must pass through message queues located in shared memory and using algorithms that enable concurrent accesses.
Naive implementations of message queues can use locks for mutual exclusion, but better implementations exploit the fact that message queues, like also arrays, can be dynamically partitioned using atomic fetch-and-add instructions, so that many threads can access concurrently a message queue, without using either mutual exclusion or optimistic accesses (which may need retries).
It is possible to have an operating system where there exists no shared state between threads, with the exception of the shared message queues.
Because message queues can be implemented without the need for mutual exclusion, it is possible to have an operating system where mutual exclusion (i.e. locks) is not used anywhere.
Whether an operating system without shared state between threads can have a performance comparable with e.g. Linux or Windows, is an open problem.
The lack of shared state does not mean that superfluous copies are needed. The messages may contain pointers to buffers in shared memory through which the bulk of the data is transferred between threads, but those buffers always have a current owner, i.e. the receiver of the message, and no other thread attempts to access them, including the sender of the message, which has written the buffer before sending the message.
I did build something very similar[1] a few months ago.
For me the core idea was that I wanted two things:
* Simple persistence by default, not bolted on (files, sqlite, postgres). Each actor is an Elm-like init/update/view set of functions and a storage type. That storage type is saved after every update and can be offloaded to disk while the app doesn't receive new messages. So building durable state is very simple (there are some mechanisms for ephemeral state as well).
* Actor based capabilities, an actor has access to other actors that provide capabilities. Because actors can also be created ad-hoc with custom code (the language is a lisp-like language) you can narrow down capabilities as much as you'd like. For example if you have access to make arbitrary HTTP requests, you can create an ad-hoc actor that delegates making HTTP requests only to a certain domain and pass it. A capability is just the address of another actor.
With these two primitives (+ a content-addressable store underneath) a very capable and interesting system emerged IMO. You can have thousands and even millions of applications running, they hibernate automatically and only consume CPU when they receive a message. Clicks, typing, etc is all events on applications that receive it.
Most OS stuff can be hidden behind special actors, and you can give capabilities by providing those addresses.
THere's a pic and some more explanations at BlueSky[2]
I absolutely love actors and what I really wish existed (and where Rust/Embassy/Ector get really close to and where QuantumLeaps has somewhat of a monopoly on) is a full embedded actor system toolchain.
Interrupts and timers are such native embedded concepts that fit into hardware, its literally a perfect fit for an actor system.
UNIX had no threads originally. Processes are similar to actor model. You create pipe and you exchange bytes between processes.
Of course there are more ways to exchange data between processes, like explicitly allocating shared memory. But "idiomatic" way seems to me pretty much similar to actors.
Ime with Akka and Beam, the main drawback of actor systems is debugging. Because you’ve now forced your problem into a distributed problem always. Beam is much better at least since you can execute commands in the runtime to check things. Akka is almost impossible and I don’t miss working with it at all. Unclear here if the author has thought about it as they focus on concurrency bugs which imo are generally easier to reason about in a traditional threaded system.
With actor systems with no shared memory and explicit state implementing time traveling debug support is rather straightforward and gives you a record of all state transitions not just a call stack. This is vastly more useful.
The drawback is that one can have stack trace in prod but no time-traveling debugging. But then a typical workaround is to log explicitly state transitions. Depending on how it is done it can be sufficiently ergonomic and still gives more information than stack traces.
I also had this experience with Akka. For people who were able to build up a good mental model of what was what, it wasn't so bad, but still not as efficient as with a standard model. And of course, not all people are capable of having a sufficient mental picture and were totally lost.
I liked it, but my takeaway was that the negatives outweighed the positives, especially when factoring in not everyone was capable of dealing with it. I'm sure there are use cases where that calculus changes, but not the ones I had.
I’ve never worked with Akka but I’ve always found GenServers on the BEAM pretty easy to debug. You outline all of your state transitions and you can usually see why something is going wrong.
What do you mean by "outline all of your state transitions"? How do you outline them? Where? Is that something you do in the code? In the documentation? In your debugging setup?
Neat! I've been working on generalizing the Motoko(actor based language that compiles to warm) to a general runtime at https://moxzi.ai, and I hadn't considered pushing it down to the OS level. If you are looking for a higher level actor based language motoko is worth a look.
I’m curious to see whether “no pre-emption” will hold as applications scale up. Given the aggressive enforcement of time-slicing, I’d have trouble writing, say, tasks that lends itself to a recursive call structure yet yields in a predictable amount of time.
(I wrote a parser-compiler for the classic Macintosh OS, which notoriously had cooperative multitasking… by the end I ended up simulating pre-emption by sprinkling calls to a routine that did “check timer, yield to OS if needed”.)
> A handler always runs to completion in a bounded amount of time
What if I want to start a computation and I can't reason how long it takes, so that the OS kills my program, because it spent too much time? In a traditional OS it's not a problem, it can interrupt my program at any moment and resume it later.
> An idle actor instance has no stack, and no register context to save
If I have no stack, what can I use to save program state? Do I need to mess with global variables for this?
An interesting project, I say as a fan of actor pattern at the application level.
> A single handler execution has a limited time window and must run to completion in a small time window. The kernel enforces this by killing any instance that exceeds the limit.
And then what? If the actor was in the process of writing a file, what is left of the bytes on disk? Does another or the same actor get restarted to complete the write without introducing corruption?
Also, how does this system handle multi-threading inside an actor? The prior post says Linux apps are supported so it's not just actors all the way down. Do multi-threaded Linux programs starve the OS?
And what is the shape of the OS kernel? Presumably there is a core monolith that handles message passing and execution. Is it ignorant of the hardware? "I can change out a graphics driver, storage driver, or an application all without a reboot" implies the answer is "yes". But, that can't be the whole answer because the core must know about hardware resources in order to know how to execute and kill actors.
Maybe a follow up post covering these core OS issues?
> If the actor was in the process of writing a file, what is left of the bytes on disk? Does another or the same actor get restarted to complete the write without introducing corruption?
It wasn't spelled out, but my reading is that an actor is never "in the process of writing a file" because that would be a blocking operation. It probably has to start with a message which requires data to be written and then copies data into a buffer and generates a message to the kernel that the buffer needs flushed along with a message to its future self about what to write next, then exits. If it wrote everything it needed into the available buffer, it would emit a different message saying the file needs closed. AFAIK it all boils down to the same coding style as Node.js where every blocking file operation becomes an async re-entry point.
Hmm. Then the GP’s question ends up being about transactions (interrelated series of messages sent by an actor). What happens if an actor is killed by timeout in the midst of sending and waiting for responses from a bunch of “append bytes to file” messages?
This is cooperative multi-tasking all over again. I don't think it's for a real, widely used OS.
Not only would the file get cut off, but tasks will run faster on one machine than on another, meaning that your program may run fine on your computer, but what it'll do on another is anybody's guess.
It also uses one thread on one processor, so it basically throws a lot of performance out of the window. Perhaps it works on embedded, although the idea of a time limit on every message seems rather harsh.
Im familiar with the actor pattern but completely naive to their implementation. I’m having trouble imagining a few things and might be way off the mark. A few questions that might help others resolve my confusion:
1. Are there as many processes as there are cores on the CPU?
2. Is there a single message queue shared across cores?
3. Presumably two networking actors or two filesystem actors could be processing different messages on different cores and hardware resources can still be contested?
> 3. Presumably two networking actors or two filesystem actors could be processing different messages on different cores and hardware resources can still be contested?
I won't presume this is how DbgOS works, but considering that the author mentions writing drivers as actors, I would imagine that two actors would not be allowed to represent the same underlying resource. You would have one actor for each device, then and only then can any number of other concurrent actors build functionality on top of it through message passing.
I'm only familiar with implementing run-to-completion actors. If a message is sent to an actor, the actor's behavior needs to run to process the message. You could have a message queue per thread (physical or logical core), or a message queue per actor, with a separate scheduler to decide when each actor should get a chance to run. There are obvious performance benefits to keeping communication local to a core, so hierarchical architecture where there are core-local actor networks and cross-core networks can make sense.
As to your final question, actors processing messages is a computation, i/o of any kind would involve sending messages to other lower-level i/o actors that multiplex or coordinate access to individual hardware resources.
1) Typically the number of actors and hardware threads are disconnected and it uses some MxN scheduler. There's a lot of related techniques here, green threads, user threads, coroutines, fibers, etc. Though the implementation under discussion here only uses one hardware thread, and looks a lot like the single threaded models like how node wraps libuv.
2) It can be thought of as at least one message queue per actor.
Yep, it's super fun to write your own OS. Especially in the AI era to accelerate theory testing as the one attached in the blog post.
If I agree with it, I don't know.. I have my OS development testing my own theories for last 6 months.. and again.. all I can say is that it's fun, thoughtful and interesting to pursue product management learning points in such project. Completely doable for a single person to have something that works and is complete and from scratch. No Temple OS bullshit for schizophrenics.. No need to be cursed by Perkele like Linus to find devil's skills to convince the community to adopt a school project and go nuts with global adoption..
just for fun, real, yet homebrew OS that can run on your own hardware.. or cyberdeck that may be your next project when you get your OS running on boring mundane laptop just fine.
That has already been won, outside BSD/Linux universe, most OSes are hybrid, with tons of userspace processes and drivers, also microkernels have won on the embedded RTOS space.
Also running cloud software, serverless runtimes, or distroless containers, on top of type 1 hypervisors, is pretty much a microkernel like architecture.
Yeah, the thrust of the pushback was something along the lines of "great, your individual modules are small enough to reason about individually, but now you've dumped too much complexity into the communication channels instead"
There are some serious drawbacks with this being the fundamental model of an OS. An OS needs to be able to handle everything that you might want that OS to be able to do. A strict actor model has some performance issues, because it requires all message communication to be copied around. There are some pathological cases for this where you need lots of copying and communication for things that are not difficult with sharing. Even Erlang actually doesn't have full memory isolation, because it can share immutable binary terms between processes and do garbage collection on the references rather than copying them around entirely. Since the language has no way to modify the immutable values, it's safe, but it also means the naive understanding of "no shared state" is not actually true, in a way that will matter to an OS.
You can also get some performance issues depending on how your route messages; for instance Erlang does this pattern matching thing on messages but that can let them back up and create subtle and hard-to-diagnose memory leaks, and subtle performance issues trying to pick certain messages out of a queue. In a specific Erlang program the solution is, broadly speaking, "don't do that", but an OS must be ready for vastly more pathological conditions than "a specific Erlang program".
Also, cooperative multitasking at the operating system is well explored and a known major failure. It damn near killed MacOS and required a massive and expensive effort to get MacOS off of it before it did kill it. In a nutshell, as you scale up the probability that at least one process will misbehave and fail to give up its time slice approaches one, at scales much smaller than what constitutes a modern OS. I don't like it even today even in my own code, but the only reason it is even remotely viable is that it is still contained to single OS processes and even if one OS process has something not cooperating the surrounding OS is fundamentally pre-emptive. If that was not the case, all "async" code would be dead in the water today and nobody would be using it at all. If an OS is going to be actor based I would 100% expect those actors to be threads, in the sense of being independently scheduled entities. not being cooperatively scheduled.
Or, to put it another way, the reason anyone is using cooperative multitasking today is precisely because they're using it in an OS that is ensconcing them within a threaded environment at the OS level (where here an "OS process" is a thread for these purposes). If you take that layer away and everything is running in the same cooperative context, suddenly the costs of cooperative multitasking literally exponentially skyrocket and it is completely unappealing.
I also think there's some dissonance between having Rust and having a requirement that all code be actors within a given OS, because the two overlap a lot. Actors are already a fairly viable mechanism for managing memory, if you just don't let actors fiddle with other actor's memory. So this super rich and complicated borrowing mechanism is really doing a lot of work that is redundant to the actor boundary. "Actors" as one technique in a Rustacean's toolbelt is a fine choice, but if the OS itself is going to lift up actors as the one true and fundamental approach to writing code, Rust burns a lot of design budget on problems that are suddenly nowhere near as large anymore, because the OS really ought to be providing isolation fundamentally.
Now, of course, if you're just playing around, hey, do as you like. But as a serious foundation for an OS that others might use there are major issues here.
On the plus side, as Erlang demonstrates, if you make it so actors can communicate across the network then you get the ability to build large computers out of small ones with some relative ease. Though to raise actors up to the OS level, you might need to do something that Erlang really doesn't and make a real, type-level distinction between local actors and actors that might be remote, because actors over the network necessarily have unreliable message passing, and implementing local OS services with "unreliable message passing" will add additional complication to every such interaction. Being able to do what Go does with channels and make message handoff and reception an explicit synchronization point is really, really convenient, and can even be harnessed to do some OS-level optimizations like "hey OS, here's my buffer, you're the OS and specially blessed so instead of sending me a copy of a byte buffer for me to then copy into my own local representation why don't you just take this handle to some memory and slam it straight in there" fairly safely, mitigating some of the performance impacts I mentioned at the top.
"We need a way to send a request to another actor, and provide it a way to send back a response that can be connected to the original request. For that, we have a “reply slot”, represented as a ReplyTo<R> in the code for actors."
It's probably partly due to habit but I like the BEAM solution to this, i.e. provide your sender ID and let the receiver figure it out. Oftentimes you don't care about a response, you just want to flick a switch at a distance or throw some garbage into a bucket.
For me it makes the basic model simpler to hold in my mind and it's been a nice learning experience to look at how stuff on the BEAM gets from there to state machines and generic servers and supervisors and so on.
One of the nicest things with the BEAM is that it feels like I have an OS available when programming. I don't get that with threading in e.g. Java, and I don't think I'd get it from Golang either.
Does Rust have pattern matching on function declarations? I.e. could the match-block be switched for several handle-functions instead in the example? If not, then I think I prefer the BEAM way there too, it's quite nice to break out the message handlers into functions matching on the message instead of going through a match/case and then into the actual handlers.
The preemptive multitasking on the BEAM is convenient too, it almost always gives the result I want.
I don't see an example in TFA of how the actors are addressed, do they get a number when instantiated or somesuch and then one does like a send-syscall with that number?
> One of the nicest things with the BEAM is that it feels like I have an OS available when programming. I don't get that with threading in e.g. Java, and I don't think I'd get it from Golang either.
I certainly feel like that when doing Java and .NET runtimes, Java especially is what made me stop caring about POSIX.
Both are the closest I have been able to do in mainstream to the OS abstraction layers, past my Smalltalk and Lisp experiences.
> Does Rust have pattern matching on function declarations?
Rust supports patterns in function declarations, but not for the purposes you're thinking of. In function arguments, patterns are required to be irrefutable, so no redeclaring a function with different refutable patterns each time. Rust only wants a single source of truth for each function (possibly attributable to an allergy of anything that could be mistaken for C++-style function overloading), and since Rust pointedly declines interprocedural type inference, redeclaring your function multiple times with full type annotations every time would just be more verbose anyway (in contrast to something like Haskell, which supports what you're asking for but allows type inference in function signatures).
OLd(er) person here. If you want look at earliest Actor models then look at COBOL programs from 70s that used queues (it's part of COBOL standard).
Programs would read from specific queues for input data, transform that data and then write some to data stores and some to downstream queues. This created DAG environments for data and transaction flow.
Scaling in these environments was done by monitoring load and back pressure in the queues and firing multiple readers. Transaction Processing Monitors like VRX and CICS managed this at OS level and the COBOL programs managed at unit level.
COncurrency was running multiple units reading from same queue to do same function.
this is one reason why a ton of these older systems still running.
DAG workflow, automatic balancing, queue based actor models with transactions.
Seems like what is old is new again.
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.
So Factorio.
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.
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.)
> 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.
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.
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.
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.
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.
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.
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.
> 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.
I am a bit skeptical of the non-blocking claims, as actor systems usually make several tradeoffs, that handle the classical 'blocking' issue differently (by which I mean I read a 100MB file synchronously on the UI thread, and the program appears to freeze).
Classical actor systems at their simplest only support sending one-way messages, and these are indeed non-blocking.
But they are not very powerful either. People usually introduce the 'remote procedure call' on top of this, by which actor A can call actor B and expect B to respond. You can do this with corellation IDs for example.
The question is what does actor A do while waiting for 'B'? In the simplest form it continues to serve other messages, making the actor reentrant, which can create incredibly surprising scenarios as code executes while you don't expect to changing actor fields in unexpected ways.
Or you can have actor A wait to finish processing the call to 'B'. But now you have blocking, as 'B' can prevent anyone talking to 'A' from making progress.
Or you can do something computer-sciencey, like doing transactions and specifying the conditions under which A can server multiple ongoing requests, and how to reconcile them.
I'm sure there are many options, but actors have been a cool idea for a while, and many event driven paradigms borrow from it, that are incredibly widespread to the point that I'm sure most people have programmed in a system before, and have experienced 'callback hell'.
So they are not a panacea.
> In the simplest form it continues to serve other messages, making the actor reentrant, which can create incredibly surprising scenarios as code executes while you don't expect to changing actor fields in unexpected ways.
That's probably why GUI programming is so hard and every GUI sucks.
Anything that happens outside RAM requires you to respond to every possible input in the middle of any possible operation
May I recommend the following 2 talks on this subject:
https://www.youtube.com/watch?v=37wFVVVZlVU Panel Discussion with Sir Tony Hoare, Joe Armstrong, and Carl Hewitt
https://www.youtube.com/watch?v=7erJ1DV_Tlo Hewitt, Meijer and Szyperski: The Actor Model (everything you wanted to know...)
The first one is a rare gem: a conversation among the creators of the foundational concurrency models. Carl Hewitt (Actor Model), Tony Hoare (CSP, Communicating Sequential Processes, which inspired Go's goroutines and channels), and Joe Armstrong (co-creator Erlang).
You can extend this with "linear type" message passing where you transfer ownership of an object. That avoids physically copying memory and the sender loses write access to enforce the one writer at a time constraint.
It means a pipeline of actors can process a file with the same memory usage and only a tiny bit more CPU than a monolithic program, but it stays isolated and hot swappable.
This might already be implemented in the OS but the post doesn't mention it.
The BEAM on Erlang sort of does this with its global binary heap so you can have multiple readers. The binary must be larger than 64 bytes so it's stored on the global binary heap instead of copied onto process heaps. Its not really linear type though as there is no transfer since all data is immutable.
Implementing linear messages at the OS level is a cool idea. I’ve loved building linear types in my language, they’re super nice to work with and give you some good tooling and compiler options. I’ll bet an OS could do a lot with the idea.
The headline advertises 'no threads', but in the article, it mentions all actor methods are non-blocking, and async. Not blocking what?
The whole purpose of async is to have a message pump thread, and allow concurrency by yielding the timeslice. It's also needed because many async runtimes interact with APIs that need to be called from a single main OS thread.
I would presume an OS designed to be all actors, all the way down would do away with the need for a message pump thread, and single threaded APIs. In this case, cross-actor calls might as well be sync, with required preemption handled on the OS level.
Having to pay the async overhead over 100% of cross-actor calls is very expensive.
There are two schools of thought for this.
One is the poll model, you ask the OS when you can use something.
The other one is the completion model, where you ask the OS to do something on your behalf and ask it when it’s done.
In the former you are the mailbox yourself, in the latter the OS is the mailbox.
When you are the mailbox yourself threads are kind of needed. When the OS is the mailbox it can implement them however it wants to.
I’d guess this OS is doing Mailbox duty itself instead of letting userspace handle it.
There is an extra step after "you ask the OS to do something on your behalf and ask it when it’s done".
That is "you ask the OS to do something on your behalf and you do not have to check when it is done", because you have a unique queue where you receive notifications about everything that is of interest for you, including the completions of I/O activities that you have requested previously.
"You ask the OS to do something on your behalf and ask it when it’s done" was an ancient method to perform asynchronous I/O, which survived in many operating systems much more years than it should. Continuing to use such a method today is a mistake.
The best method for asynchronous I/O is with a unique input queue, like in the Linux io_uring. The second best method, because it can be used to implement a unique input queue, is with what in DEC RSX-11M was called "Asynchronous System Trap Service Routine", i.e. a callback function to be invoked upon I/O completion, which was inherited from DEC RSX-11M into DEC VMS, from where it was inherited into Microsoft Windows NT, and then in 1994 MS Windows NT 3.5 introduced the "I/O Completion Ports", which was AFAIK the first improvement in asynchronous I/O handling after what DEC RSX-11M did 20 years earlier, in 1974 (which was again the first improvement over what IBM PL/I already had in 1964, when it had the equivalent of WaitForMultipleEvents, but in a more powerful variant than in Windows NT).
I/O uring is built upon this, with it i can serve 155 http responses per syscall, whereas with epoll i can serve 0,2.
Having your OS do the batching for you can make it twice as fast.
My new http implementation went from 3 million responses per second per thread to 6 million, just from replacing epoll and non blocking sockets with liburing and batching.
> The headline advertises 'no threads', but in the article, it mentions all actor methods are non-blocking, and async. Not blocking what?
I think the very brief answer to that is: "Processes." as in the general concept of communicating processes. How those are actually implemented on another layer depends on the platform. You can also run an actor system on a machine, that can only do one thing at a time, using a single CPU core. The work the process does is not blocking, but the platform might not have the capability to do more than one thing at a time. But this is different from work being inherently sequential.
«Threads» imply «shared state» within the confines of the same process, hence the need for locking primitives, mutexes, and alike.
«Actors» imply «no shared state» – there is a message inbox and a message outbox, but the state is private to the actor.
Both can be asynchronous.
I think this taxonomy is not good. It’s comparing apples to oranges, or apples to fruit sugars or something.
Threads are not a programming paradigm or style, any more than a CPU is a programming paradigm or style. They’re a tool, an existential piece of the landscape which can be used to perform paradigms/styles. Like CPUs, they do have affinity for certain use cases, but the car is not the road trip.
If threads don’t share state, they are effectively the same as processes. The whole purpose of having threads in addition to processes is to share state. If you don’t share state, you don’t need threads. That’s what the blog post means by “an OS with no threads”.
It’s pre-coffee, and I totally disagree “threads are not a programming paradigm”. But the best way to do that is to say that the car IS the road trip and it’s a fundamentally different thing if you use a train.
Threads are an OS level concept introduced by a kernel, e.g. the Linux kernel. If you do not have an OS at all, you do not have threads (lets ignore hardware threading for the sake of the argument). You just have the core itself be occupied by the actor scheduler, but no thread scheduler.
Blocking is not a threading or even OS concept. Blocking is a CPU core and programming language concept derived from sequential processing. Blocking means that instructions behind the block are not being executed while the block is in progress.
In the actor model, sending a message must never prevent the execution of instructions that follow after sending the message. The continued execution of further instructions must be guaranteed until the actor has processed the message. Responses must be received through the actor's mailbox.
Since blocking as an absolute concept may not make much sense, because all sequential processes (e.g. execution of an instruction) are blocking temporarily, the author decided instead to define a time bound, so if mail box processing takes too long, simply because the algorithm is CPU intensive, the author considers it blocked as well and schedules the next actor.
Edit: I guess the confusion comes from the fact that Rust's async facility automatically converts the code into a state machine that is compatible with actor execution semantics, but technically violates the spirit of actors.
I look at it differntly. There is no fundamental difference between async paradigm and threads. The only difference is where the call stack is.
It just happens that in threads, there is this magical place called stack that you can SUPER fast allocate memory for new function frame. If you have a complex program that uses many deep very deep calls to functions withing functions within functions, you dont need to deal with register allocation or even "local stack frame" for local variables allocations. You just zip in and zip out of the "thread" stack all the time, millions times per second.
The disadvantage is that if for whatever reason a deeply nested thing needs to do _something_, typically I/O, then there is no easy way to yield and allow someone else to use ALU. One option is to change stack register to some other stack and continue other stream of compute. This done by OS is called a context switch.
However, for certain problems, there is an alternative - async. In async the "stack" for local variables is more explicit, very often on the heap, and is managed differently. Every time you are calling a nested function it also needs to store the local variables somewhere, so either you emulate stack somehow (in which case this is not much differnet than normal thread) or allocate the nested function local variables space using memory allocator on heap or special memory.
This is great beause it allows you to reduce the cost of a context switch - now you don't need to change the stack pointer and save context, becasue context is by definition saved in the async block. Asnc also allows you to NOT overcommit on stack size for some future deep deep nested fucntion calls that might never happen. In async you know exactly where you can yield and can plan for it.
However it's not like these two models are fundamentally different. It's the same problem of "where the local variables live" and "how to allocate this memory". We have far bigger problem - due to historical reasons "blocking" is a thing, but this is is only because we made mistakes designing operating systems (I'm looking at you fsync, open, close, or even bpf() syscalls).
I do think they’re fundamentally different, for two reasons:
1. The decision of when to switch routines is more consequential than the cost of stack or context switching. Letting the OS decide results in behavior that is consistently fair for all programs, caveat scheduler bugs. Letting user code decide results in behavior that is only as fair as a given program. Writing code in the latter environment entails wrestling with the reality that it may not run to completion unless other code in the environment lets it. That applies in async programming to a much wider range of situations than kill signals/aborts, which are the only even slightly analogous things in threaded programming.
2. Async is a subset of threaded programming (it has a hardware stack, and can call typical context-switchful code if it wants to block).
On ancient single-core single-thread CPUs, threads were indeed a concept introduced by the operating system, and the use of threads was completely optional.
On modern CPUs, which have many hardware threads, the operating system and the user programs must handle at least the number of hardware threads, e.g. 32 threads on an AMD 9950X.
Implementing more threads than the hardware threads is optional, but the hardware threads must have their own states and stacks and if they exchange messages the inter-thread messages must pass through message queues located in shared memory and using algorithms that enable concurrent accesses.
Naive implementations of message queues can use locks for mutual exclusion, but better implementations exploit the fact that message queues, like also arrays, can be dynamically partitioned using atomic fetch-and-add instructions, so that many threads can access concurrently a message queue, without using either mutual exclusion or optimistic accesses (which may need retries).
It is possible to have an operating system where there exists no shared state between threads, with the exception of the shared message queues.
Because message queues can be implemented without the need for mutual exclusion, it is possible to have an operating system where mutual exclusion (i.e. locks) is not used anywhere.
Whether an operating system without shared state between threads can have a performance comparable with e.g. Linux or Windows, is an open problem.
The lack of shared state does not mean that superfluous copies are needed. The messages may contain pointers to buffers in shared memory through which the bulk of the data is transferred between threads, but those buffers always have a current owner, i.e. the receiver of the message, and no other thread attempts to access them, including the sender of the message, which has written the buffer before sending the message.
I did build something very similar[1] a few months ago.
For me the core idea was that I wanted two things:
* Simple persistence by default, not bolted on (files, sqlite, postgres). Each actor is an Elm-like init/update/view set of functions and a storage type. That storage type is saved after every update and can be offloaded to disk while the app doesn't receive new messages. So building durable state is very simple (there are some mechanisms for ephemeral state as well).
* Actor based capabilities, an actor has access to other actors that provide capabilities. Because actors can also be created ad-hoc with custom code (the language is a lisp-like language) you can narrow down capabilities as much as you'd like. For example if you have access to make arbitrary HTTP requests, you can create an ad-hoc actor that delegates making HTTP requests only to a certain domain and pass it. A capability is just the address of another actor.
With these two primitives (+ a content-addressable store underneath) a very capable and interesting system emerged IMO. You can have thousands and even millions of applications running, they hibernate automatically and only consume CPU when they receive a message. Clicks, typing, etc is all events on applications that receive it.
Most OS stuff can be hidden behind special actors, and you can give capabilities by providing those addresses.
THere's a pic and some more explanations at BlueSky[2]
[1] https://tangled.org/dzi-ban.bsky.social/KokoroOS/tree/master [2] https://bsky.app/profile/dzi-ban.bsky.social/post/3murg4lhmt...
I absolutely love actors and what I really wish existed (and where Rust/Embassy/Ector get really close to and where QuantumLeaps has somewhat of a monopoly on) is a full embedded actor system toolchain.
Interrupts and timers are such native embedded concepts that fit into hardware, its literally a perfect fit for an actor system.
UNIX had no threads originally. Processes are similar to actor model. You create pipe and you exchange bytes between processes.
Of course there are more ways to exchange data between processes, like explicitly allocating shared memory. But "idiomatic" way seems to me pretty much similar to actors.
this is talking about the kernel not the userland.
Yep, and poll(2) (or later select(2)) to coalesce all possible events into one logical event queue.
Ime with Akka and Beam, the main drawback of actor systems is debugging. Because you’ve now forced your problem into a distributed problem always. Beam is much better at least since you can execute commands in the runtime to check things. Akka is almost impossible and I don’t miss working with it at all. Unclear here if the author has thought about it as they focus on concurrency bugs which imo are generally easier to reason about in a traditional threaded system.
With actor systems with no shared memory and explicit state implementing time traveling debug support is rather straightforward and gives you a record of all state transitions not just a call stack. This is vastly more useful.
The drawback is that one can have stack trace in prod but no time-traveling debugging. But then a typical workaround is to log explicitly state transitions. Depending on how it is done it can be sufficiently ergonomic and still gives more information than stack traces.
It's a state machine, how was it hard to debug? Was it the actual distributed (Akka Cluster) bits or just the system in general?
I also had this experience with Akka. For people who were able to build up a good mental model of what was what, it wasn't so bad, but still not as efficient as with a standard model. And of course, not all people are capable of having a sufficient mental picture and were totally lost.
I liked it, but my takeaway was that the negatives outweighed the positives, especially when factoring in not everyone was capable of dealing with it. I'm sure there are use cases where that calculus changes, but not the ones I had.
I’ve never worked with Akka but I’ve always found GenServers on the BEAM pretty easy to debug. You outline all of your state transitions and you can usually see why something is going wrong.
What do you mean by "outline all of your state transitions"? How do you outline them? Where? Is that something you do in the code? In the documentation? In your debugging setup?
In your call handlers you handle messages e.g.
def handle_cast({:increment, by}, state), do: {:noreply, state + by}
Obviously you can be as loos or rigorous as you want and go all the way up to implementing a finite state machine with aggressive guards.
You can use observer to see what's happening with various processes/actors.
Neat! I've been working on generalizing the Motoko(actor based language that compiles to warm) to a general runtime at https://moxzi.ai, and I hadn't considered pushing it down to the OS level. If you are looking for a higher level actor based language motoko is worth a look.
I’m curious to see whether “no pre-emption” will hold as applications scale up. Given the aggressive enforcement of time-slicing, I’d have trouble writing, say, tasks that lends itself to a recursive call structure yet yields in a predictable amount of time.
(I wrote a parser-compiler for the classic Macintosh OS, which notoriously had cooperative multitasking… by the end I ended up simulating pre-emption by sprinkling calls to a routine that did “check timer, yield to OS if needed”.)
> A handler always runs to completion in a bounded amount of time
What if I want to start a computation and I can't reason how long it takes, so that the OS kills my program, because it spent too much time? In a traditional OS it's not a problem, it can interrupt my program at any moment and resume it later.
> An idle actor instance has no stack, and no register context to save
If I have no stack, what can I use to save program state? Do I need to mess with global variables for this?
An interesting project, I say as a fan of actor pattern at the application level.
> A single handler execution has a limited time window and must run to completion in a small time window. The kernel enforces this by killing any instance that exceeds the limit.
And then what? If the actor was in the process of writing a file, what is left of the bytes on disk? Does another or the same actor get restarted to complete the write without introducing corruption?
Also, how does this system handle multi-threading inside an actor? The prior post says Linux apps are supported so it's not just actors all the way down. Do multi-threaded Linux programs starve the OS?
And what is the shape of the OS kernel? Presumably there is a core monolith that handles message passing and execution. Is it ignorant of the hardware? "I can change out a graphics driver, storage driver, or an application all without a reboot" implies the answer is "yes". But, that can't be the whole answer because the core must know about hardware resources in order to know how to execute and kill actors.
Maybe a follow up post covering these core OS issues?
> If the actor was in the process of writing a file, what is left of the bytes on disk? Does another or the same actor get restarted to complete the write without introducing corruption?
It wasn't spelled out, but my reading is that an actor is never "in the process of writing a file" because that would be a blocking operation. It probably has to start with a message which requires data to be written and then copies data into a buffer and generates a message to the kernel that the buffer needs flushed along with a message to its future self about what to write next, then exits. If it wrote everything it needed into the available buffer, it would emit a different message saying the file needs closed. AFAIK it all boils down to the same coding style as Node.js where every blocking file operation becomes an async re-entry point.
Hmm. Then the GP’s question ends up being about transactions (interrelated series of messages sent by an actor). What happens if an actor is killed by timeout in the midst of sending and waiting for responses from a bunch of “append bytes to file” messages?
This is cooperative multi-tasking all over again. I don't think it's for a real, widely used OS.
Not only would the file get cut off, but tasks will run faster on one machine than on another, meaning that your program may run fine on your computer, but what it'll do on another is anybody's guess.
It also uses one thread on one processor, so it basically throws a lot of performance out of the window. Perhaps it works on embedded, although the idea of a time limit on every message seems rather harsh.
I would love to see a Smalltalk implementation on top of this.
E wasn't Smalltalk but was designed by Smalltalk enjoyers: https://web.archive.org/web/20261128134610/www.erights.org/
Im familiar with the actor pattern but completely naive to their implementation. I’m having trouble imagining a few things and might be way off the mark. A few questions that might help others resolve my confusion:
1. Are there as many processes as there are cores on the CPU?
2. Is there a single message queue shared across cores?
3. Presumably two networking actors or two filesystem actors could be processing different messages on different cores and hardware resources can still be contested?
> 3. Presumably two networking actors or two filesystem actors could be processing different messages on different cores and hardware resources can still be contested?
I won't presume this is how DbgOS works, but considering that the author mentions writing drivers as actors, I would imagine that two actors would not be allowed to represent the same underlying resource. You would have one actor for each device, then and only then can any number of other concurrent actors build functionality on top of it through message passing.
I'm only familiar with implementing run-to-completion actors. If a message is sent to an actor, the actor's behavior needs to run to process the message. You could have a message queue per thread (physical or logical core), or a message queue per actor, with a separate scheduler to decide when each actor should get a chance to run. There are obvious performance benefits to keeping communication local to a core, so hierarchical architecture where there are core-local actor networks and cross-core networks can make sense.
As to your final question, actors processing messages is a computation, i/o of any kind would involve sending messages to other lower-level i/o actors that multiplex or coordinate access to individual hardware resources.
1) Typically the number of actors and hardware threads are disconnected and it uses some MxN scheduler. There's a lot of related techniques here, green threads, user threads, coroutines, fibers, etc. Though the implementation under discussion here only uses one hardware thread, and looks a lot like the single threaded models like how node wraps libuv.
2) It can be thought of as at least one message queue per actor.
3) Yep.
Interesting concept Tim, I borrowed some ideas from you
https://peterretief.org/posts/actors-with-mailboxes/
Yep, it's super fun to write your own OS. Especially in the AI era to accelerate theory testing as the one attached in the blog post.
If I agree with it, I don't know.. I have my OS development testing my own theories for last 6 months.. and again.. all I can say is that it's fun, thoughtful and interesting to pursue product management learning points in such project. Completely doable for a single person to have something that works and is complete and from scratch. No Temple OS bullshit for schizophrenics.. No need to be cursed by Perkele like Linus to find devil's skills to convince the community to adopt a school project and go nuts with global adoption..
just for fun, real, yet homebrew OS that can run on your own hardware.. or cyberdeck that may be your next project when you get your OS running on boring mundane laptop just fine.
perhaps it is time to discuss the torvalds-vs-tannenbaum debate once again in $CURRENT era ?
That has already been won, outside BSD/Linux universe, most OSes are hybrid, with tons of userspace processes and drivers, also microkernels have won on the embedded RTOS space.
Also running cloud software, serverless runtimes, or distroless containers, on top of type 1 hypervisors, is pretty much a microkernel like architecture.
Were they talking about actor models too?
I remember the debates about monolithic vs microkernel designs. But it was so long ago that I can’t remember any of the specifics.
Yeah, the thrust of the pushback was something along the lines of "great, your individual modules are small enough to reason about individually, but now you've dumped too much complexity into the communication channels instead"
Ahhh yes. Thanks for sharing.
> ... debates about monolithic vs microkernel designs
message passing was the mechanism underneath the debate, and not the headline afaik.
There are some serious drawbacks with this being the fundamental model of an OS. An OS needs to be able to handle everything that you might want that OS to be able to do. A strict actor model has some performance issues, because it requires all message communication to be copied around. There are some pathological cases for this where you need lots of copying and communication for things that are not difficult with sharing. Even Erlang actually doesn't have full memory isolation, because it can share immutable binary terms between processes and do garbage collection on the references rather than copying them around entirely. Since the language has no way to modify the immutable values, it's safe, but it also means the naive understanding of "no shared state" is not actually true, in a way that will matter to an OS.
You can also get some performance issues depending on how your route messages; for instance Erlang does this pattern matching thing on messages but that can let them back up and create subtle and hard-to-diagnose memory leaks, and subtle performance issues trying to pick certain messages out of a queue. In a specific Erlang program the solution is, broadly speaking, "don't do that", but an OS must be ready for vastly more pathological conditions than "a specific Erlang program".
Also, cooperative multitasking at the operating system is well explored and a known major failure. It damn near killed MacOS and required a massive and expensive effort to get MacOS off of it before it did kill it. In a nutshell, as you scale up the probability that at least one process will misbehave and fail to give up its time slice approaches one, at scales much smaller than what constitutes a modern OS. I don't like it even today even in my own code, but the only reason it is even remotely viable is that it is still contained to single OS processes and even if one OS process has something not cooperating the surrounding OS is fundamentally pre-emptive. If that was not the case, all "async" code would be dead in the water today and nobody would be using it at all. If an OS is going to be actor based I would 100% expect those actors to be threads, in the sense of being independently scheduled entities. not being cooperatively scheduled.
Or, to put it another way, the reason anyone is using cooperative multitasking today is precisely because they're using it in an OS that is ensconcing them within a threaded environment at the OS level (where here an "OS process" is a thread for these purposes). If you take that layer away and everything is running in the same cooperative context, suddenly the costs of cooperative multitasking literally exponentially skyrocket and it is completely unappealing.
I also think there's some dissonance between having Rust and having a requirement that all code be actors within a given OS, because the two overlap a lot. Actors are already a fairly viable mechanism for managing memory, if you just don't let actors fiddle with other actor's memory. So this super rich and complicated borrowing mechanism is really doing a lot of work that is redundant to the actor boundary. "Actors" as one technique in a Rustacean's toolbelt is a fine choice, but if the OS itself is going to lift up actors as the one true and fundamental approach to writing code, Rust burns a lot of design budget on problems that are suddenly nowhere near as large anymore, because the OS really ought to be providing isolation fundamentally.
Now, of course, if you're just playing around, hey, do as you like. But as a serious foundation for an OS that others might use there are major issues here.
On the plus side, as Erlang demonstrates, if you make it so actors can communicate across the network then you get the ability to build large computers out of small ones with some relative ease. Though to raise actors up to the OS level, you might need to do something that Erlang really doesn't and make a real, type-level distinction between local actors and actors that might be remote, because actors over the network necessarily have unreliable message passing, and implementing local OS services with "unreliable message passing" will add additional complication to every such interaction. Being able to do what Go does with channels and make message handoff and reception an explicit synchronization point is really, really convenient, and can even be harnessed to do some OS-level optimizations like "hey OS, here's my buffer, you're the OS and specially blessed so instead of sending me a copy of a byte buffer for me to then copy into my own local representation why don't you just take this handle to some memory and slam it straight in there" fairly safely, mitigating some of the performance impacts I mentioned at the top.
Is it possible this guy never ran into a UI event loop? Like winmain or the Android Handler . . .
Android actually works an awful lot like this, without calling it actors.
Well most async enthusiasts haven't either :)
Another Rust OS, running (almost) on a Fairphone, https://pinnacle-os.eu/blog/fairphone-4/
Next: async/evented model? Just one giant event loop (per CPU)? /joke
You joke, but that’s … almost kinda-sorta just what a hardware interrupt controller is.
So.. message passing? Alan Kay was right all along?
"right" is one dimensional. It was always a good tool from reasoning perspective. Just not always from performance perspective
Sounds like a great follow-on project to Amoeba OS by Andrew Tanenbaum.
"We need a way to send a request to another actor, and provide it a way to send back a response that can be connected to the original request. For that, we have a “reply slot”, represented as a ReplyTo<R> in the code for actors."
It's probably partly due to habit but I like the BEAM solution to this, i.e. provide your sender ID and let the receiver figure it out. Oftentimes you don't care about a response, you just want to flick a switch at a distance or throw some garbage into a bucket.
For me it makes the basic model simpler to hold in my mind and it's been a nice learning experience to look at how stuff on the BEAM gets from there to state machines and generic servers and supervisors and so on.
One of the nicest things with the BEAM is that it feels like I have an OS available when programming. I don't get that with threading in e.g. Java, and I don't think I'd get it from Golang either.
Does Rust have pattern matching on function declarations? I.e. could the match-block be switched for several handle-functions instead in the example? If not, then I think I prefer the BEAM way there too, it's quite nice to break out the message handlers into functions matching on the message instead of going through a match/case and then into the actual handlers.
The preemptive multitasking on the BEAM is convenient too, it almost always gives the result I want.
I don't see an example in TFA of how the actors are addressed, do they get a number when instantiated or somesuch and then one does like a send-syscall with that number?
> One of the nicest things with the BEAM is that it feels like I have an OS available when programming. I don't get that with threading in e.g. Java, and I don't think I'd get it from Golang either.
I certainly feel like that when doing Java and .NET runtimes, Java especially is what made me stop caring about POSIX.
Both are the closest I have been able to do in mainstream to the OS abstraction layers, past my Smalltalk and Lisp experiences.
> Does Rust have pattern matching on function declarations?
Rust supports patterns in function declarations, but not for the purposes you're thinking of. In function arguments, patterns are required to be irrefutable, so no redeclaring a function with different refutable patterns each time. Rust only wants a single source of truth for each function (possibly attributable to an allergy of anything that could be mistaken for C++-style function overloading), and since Rust pointedly declines interprocedural type inference, redeclaring your function multiple times with full type annotations every time would just be more verbose anyway (in contrast to something like Haskell, which supports what you're asking for but allows type inference in function signatures).
What if someone wanted to do multicore number crunching??
See Connection Machine, talking across CPUs via Pvars.
neat idea!
Why does this feel like Groundhog Day and how did this make it to no. 2 on HN?