Top
Best
New

Posted by ingve 15 hours ago

An OS with no threads: The Actor Model(www.timdbg.com)
292 points | 141 commentspage 2
cestith 8 hours ago|
I have a book from years ago about writing an OS, and the example OS used in it, MMURTL, used message passing heavily but IIRC not exactly the actor model. It allowed one to swap out parts of the OS the same way, though. One could spin up a new copy and have new messages go to the new version while the old cleared its queue. You could choose to stop processing the queue in the old one and let the messages queue up to let the new one start processing the input queue once the old messages were drained.

https://bookfinder.com/search/?isbn=9780672306556

The core of the actor model is that an actor can interact with the rest of the system in three ways, not just two. It can receive messages, send messages, or spin up a new actor.

cowlevel 5 hours ago|
I think usually for hot code replacement of a stateful service, you want to freeze the incoming queue, run a state update procedure, and then resume processing of incoming messages by the new code. For a stateless service the strategy you described can work.
KentLatricia 9 hours ago||
An example of the actor model from the embedded world, QP, https://www.state-machine.com/
scroot 8 hours ago||
Posting about uFork [1] again! It's a ground-up design for a computing system that is actor based, and one of the most clever things I've encountered in recent years.

[1] https://ufork.org/

peter_retief 13 hours ago||
Interesting concept Tim, I borrowed some ideas from you

https://peterretief.org/posts/actors-with-mailboxes/

timmisiak 7 hours ago|
Very cool! There's a certain infrastructure system at Microsoft with a similar job, and folks would joke that it was an email server repurposed as a message queue.
nxobject 11 hours ago||
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”.)

cowlevel 5 hours ago||
Perhaps they could add a special kind of compute-bound actor that is preemptible but can't receive messages asynchronously, other than termination.
dapperdrake 9 hours ago||
Obviously, it won’t hold up. That is why most production systems converge on non-cooperative externally pre-empted multi-processing and multi-threading.
halfmatthalfcat 10 hours ago||
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.

cestith 8 hours ago|
One nice thing with an interrupt system handled through an actor system I suppose would the ability for an interrupt handler actor to optionally jump the line and put its messages at the front of another actor's queue while everything else is FIFO. If the input queue is external to the actor and managed by the OS (or actor library/runtime if running on top of a non-actor OS), this should be trivial to do.
Panzerschrek 13 hours ago||
> 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?

timmisiak 7 hours ago||
> What if I want to start a computation and I can't reason how long it takes

I wrote about that. It's the main weakness of this approach. You can solve it fairly easily for a linear style of task (decompression, encryption, etc.) because you can capture your state as a simple future. For cpu intensive recursive algorithms, it gets far messier.

> If I have no stack, what can I use to save program state? Do I need to mess with global variables for this?

All state is actor instance state. Kind of like any class based programming paradigm for an object not actively executing.

cowlevel 5 hours ago|||
I presume you could still make your own stack, and even save the stack pointer and program counter as part of your instance state?
dapperdrake 9 hours ago||
How does he prove termination for boundedness in the general case?

Sounds like someone is still discovering the difference between the necessary assumptions for their wish to become true and the assumptions they are actually making.

timmisiak 7 hours ago||
It's a constrained system. CPU intensive loops are easily transformed into potentially yielding futures. But not everything fits well in the model. CPU intensive recursive algorithms are messier.

There's no claim in the article that this is a superior system than threads in the general case.

frumiousirc 14 hours ago||
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?

dapperdrake 9 hours ago||
Waldo et al. (1994)

Distributed system equals partial failure and concurrent execution.

The partial failure part is where most naive map-reduce approaches get stuck. This is also where exception handling gets stuck.

nrdvana 12 hours ago|||
> 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.

zbentley 12 hours ago||
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?
jonathanamit 9 hours ago||
[dead]
tgv 12 hours ago||
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.

timmisiak 7 hours ago||
It's explicitly cooperative outside of the Linux VM that it runs. It's deployed to exactly one computer sitting on the desk next to me. So no, not widely used.

> It also uses one thread on one processor

Zero threads, and 6 processors.

Findecanor 7 hours ago||
Reminds me of Microsoft's research OS Midori which also did not have preemption: only "green threads" with async and coroutines, albeit on multiple hardware threads.

https://joeduffyblog.com/2016/11/30/15-years-of-concurrency/

chadd 3 hours ago|
Actor model programming was a big influence on the design of Cowboy (https://cowboy.inc) - in thinking about the ideal way to run 1 billion AI agents on one platform, without all of them having a standalone VM allocation.

As the author mentions, my influence was about a decade of Erlang programming which shaped how I think about concurrency, scalability, and maybe most importantly, throughput.

More comments...