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.
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.
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.
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’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”.)
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.
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?
> 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?
Interesting concept Tim, I borrowed some ideas from you
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?
Why does this feel like Groundhog Day and how did this make it to no. 2 on HN?
perhaps it is time to discuss the torvalds-vs-tannenbaum debate once again in $CURRENT era ?
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.
I would love to see a Smalltalk implementation on top of this.
Next: async/evented model? Just one giant event loop (per CPU)? /joke
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?
neat idea!
What if someone wanted to do multicore number crunching??
[dead]
[dead]
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.