Remix.run Logo
▲ An OS with no threads: The Actor Model(timdbg.com)
72 points by ingve 3 hours ago | 19 comments
▲tancop an hour ago | parent | next [-]

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.

▲Panzerschrek 8 minutes ago | parent | prev | next [-]

> 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?

▲MarceColl an hour ago | parent | prev | next [-]

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

▲vbezhenar 16 minutes ago | parent | prev | next [-]

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.

▲monocasa 11 minutes ago | parent | next [-]

Yep, and poll(2) (or later select(2)) to coalesce all possible events into one logical event queue.

▲signa11 8 minutes ago | parent | prev [-]

this is talking about the kernel not the userland.

▲thornjm an hour ago | parent | prev | next [-]

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?

▲RossBencina a minute ago | parent | next [-]

[delayed]

▲monocasa 19 minutes ago | parent | prev [-]

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.

▲frumiousirc an hour ago | parent | prev | next [-]

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?

▲signa11 2 hours ago | parent | prev | next [-]

perhaps it is time to discuss the torvalds-vs-tannenbaum debate once again in $CURRENT era ?

▲pjmlp an hour ago | parent | next [-]

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.

▲hnlmorg 2 hours ago | parent | prev [-]

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.

▲mrkeen 2 hours ago | parent | next [-]

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"

▲hnlmorg an hour ago | parent [-]

Ahhh yes. Thanks for sharing.

▲signa11 2 hours ago | parent | prev [-]

> ... debates about monolithic vs microkernel designs

message passing was the mechanism underneath the debate, and not the headline afaik.

▲cess11 32 minutes ago | parent | prev | next [-]

"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?

▲kibwen 16 minutes ago | parent [-]

> 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 that 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).

▲objectforlife an hour ago | parent | prev [-]

So.. message passing? Alan Kay was right all along?