An OS with no threads - The Actor Model
29 points by xyproto
29 points by xyproto
Other OS's have done message passing before, e.g. QNX. IIRC, they were much slower than monolithic kernels on the same hardware.
I'd also be concerned about the lack of preemption. Cooperative scheduling doesn't have a good track record. There are many work items which can consume large amounts of CPU and memory without needing to wait for external input.
I would suspect that it's relatively easy to add preemption to this OS, but more difficult to make it safe for dependency loops. Perhaps it would help if the actors had declared statically what kind of messages they sent, and to who. That would let the OS order the dependencies better.
If the actor model is taken to the extreme, it could become a lot easier to embed apps within apps, which was a promise of various systems long ago.
It's funny to see "No preemption" because the best known actor model implementation, the BEAM, is a preemptive VM.
Why do people love Erlang so much?
Because it has a very interesting and useful operational model which is extremely different from the operational model of anything derived from C.
So it is a dynamically typed programming language that uses the actor model, as far as I understand. Ignoring obvious downsides of using a dynamically typed programming language, I have never understood the appeal of using the actor model. It just doesn't make any sense to me. What benefits does it provide? Queuing requests instead of using a lock to synchronize a piece of code? In Rust, there is a library called actix, which implements the actor model, and there is also a web framework called actix-web, which, as far as I understand, originally used the actor model via actix, but then moved away from it. I don't know the reason why they moved away, but this is the only project I am aware of that actually use(d) the actor model.
Sasa Juric does a much better job than I ever could explaining why people love Erlang, Elixir, and the BEAM so much: https://www.youtube.com/watch?v=JvBT4XBdoUE
There are a lot of projects in other ecosystems that use the actor model. Akka for the JVM has existed for years and is directly inspired by Erlang. What makes the BEAM special is it fully commits to the architecture. The entire ecosystem is oriented around this architecture, which makes building complex systems much easier because you have one cohesive mental model of how the runtime operates. In many ways, a lot of what K8s and similar projects accomplished already existed in the Erlang world with far fewer moving parts.
I've been building with the BEAM for 10 years across a variety of domains. It really is the best ecosystem for building low latency, fault tolerant distributed systems that gracefully degrade under high load.
The language was created to build telecommunications networks. In that setting, dynamic typing is an advantage because they were able to upgrade software versions with zero downtime. This isn’t possible, or is at least extremely difficult with statically typed code.
As far as the actor model, this was an approach to enable resilience and fault tolerance. Erlang encourages a “supervision tree” pattern where processes can monitor other processes for failure and restart them.
One of the co-creators did his PhD on distributed systems reliability: https://erlang.org/download/armstrong_thesis_2003.pdf. Pretty much all of the ideas there were encoded into Erlang’s design. It’s not the only way to design reliable systems, but it is definitely a well-thought-out and valid one.
On the subject of queuing vs locking. I would look into queueing theory. Any form of locking and coordination is terrible for throughput. The issue is that locks prevent other work from getting done, which globally impacts performance. Asynchronous queues (ideally) allow pipelining which reduces the net amount of time needed for individual requests when observed from the outside. Look at io_uring for example and how many high performance systems it’s enabled.
Long story short, Erlang was designed for a specific type of application, with specific reliability constraints in mind. In that regard, it’s an overwhelmingly successful design. Maybe you work on a different class of problems so that design doesn’t appeal to you. That’s ok.
At risk of overlapping with EntityClay's comment, aside from green-threading what I love about actors is the supervision model. This article is my absolute favorite to reference when talking about operational reliability. https://ferd.ca/the-zen-of-erlang.html
I always entertained the idea to use a mechanism like Wasm's fuel to coerce cooperative multitasking despite non-coopertaive tasks. A bit like interrupts, but caused by a certain amount of computational progress, not by a wall clock time duration.
IIRC modern microkernels are pretty competitive, and the safety properties keep getting more valuable.
And that’s throughput, but a microkernel tends to be more reactive (it’s harder to bog it down because one task goes off the rails as most others should be able to continue independently) which is also a useful property for interactive OS.
We are experimenting with this in the context of OCaml unikernels. For several years now, we have been developing a cooperative scheduler called Miou, as Solo5 (the framework enabling us to build unikernels) is single-core and OCaml does not support preemption (we could achieve this using signals, as Go does, but interrupts are not possible with Solo5).
The fact is that we have already identified real problems with cooperative schedulers (particularly with lwt) for some of our unikernels.
Our approach with Miou is to shift the balance between executing tasks and monitoring events, so as to make our unikernels "more available".
From my point of view, if I could implement preemption, I would, but this is not currently possible within the context of unikernels (or at least, it requires more work). The "no-preemption" argument strikes me as rather weak, and there are examples showing that preemption (whether at the kernel or unikernel level) remains a worthwhile feature.
I would suspect that it's relatively easy to add preemption to this OS, but more difficult to make it safe for dependency loops.
So long as the system honours the Isolated Turn Principle, which depends upon "liveness" in the sense that there's no blocking while handling a message, just blocking waiting for the next message, then preemption cannot cause any issues that weren't reachable by a nonpreemptive system.
I did build something very similar[1] a few months ago. For me the core idea was that I wanted two things:
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/3murg4lhmt22o
The claim of "no blocking" doesn't make sense unless you bound queue size and drop messages. Otherwise, a slow consumer will lead to out of memory, or you have to statically know how to throttle producers.
Dropped messages are very hard to program against, and will probably lead to software implementations of back pressure, ie, blocking.