An OS with no threads: The Actor Model

(timdbg.com)

51 points | by ingve 2 hours ago

9 comments

  • tancop 29 minutes ago
    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.

  • MarceColl 36 minutes ago
    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...

  • cess11 0 minutes ago
    "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?

  • thornjm 16 minutes ago
    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?

  • signa11 1 hour ago
    perhaps it is time to discuss the torvalds-vs-tannenbaum debate once again in $CURRENT era ?
    • pjmlp 28 minutes ago
      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 1 hour ago
      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 1 hour ago
        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 36 minutes ago
          Ahhh yes. Thanks for sharing.
      • signa11 1 hour ago
        > ... debates about monolithic vs microkernel designs

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

  • frumiousirc 55 minutes 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?

  • objectforlife 50 minutes ago
    So.. message passing? Alan Kay was right all along?
  • gqcstore 11 minutes ago
    [dead]
  • bearcatty 1 hour ago
    [dead]