7 ms·
Ractor – a Rust Actor Framework
- helge9210 2y agoSeeing "channel" and "actors can inter-communicate, via remote procedure calls" do I understand this correctly this is not an actor model implementation?
- jatins 2y agoThat looks interesting! What's the distributed story of Ractor? Would you need a central store like Redis to serve as Actor registry? One of the promises of Elixir/Erlang is that you can call a process/Actor on different machine just like you can one on same once you put together a bunch of machines in a cluster
- stefanka 2y agoSeems to be supported > Additionally ractor has a companion library, ractor_cluster which is needed for ractor to be deployed in a distributed (cluster-like) scenario. ractor_cluster shouldn’t be considered production ready, but it is relatively stable and we’d love your feedback!
- kemiller 2y agoElixir/erlang/gleam also have the advantage that many libraries are written as servers and so automatically gain the benefits and resilience. Something all these actor frameworks can’t give you.
- brunoqc 2y agoWith gleam, how do you call an actor on another machine when you have a cluster? Do you need something like redis?
- doawoo 2y agoThe Erlang runtime and EPMD takes care of this for you. Every node in the cluster gets a name, so you can address it directly, and, every PID is unique across nodes on a cluster, so you can send messages to processes (actors) no matter where they are in the cluster. OTP is super powerful out of the box :)
- brunoqc 2y agoThanks! I'm taking a look at https://github.com/wmealing/gleam-distribution-demo/tree/main https://github.com/wmealing/gleam-distribution-demo/tree/mai... And https://github.com/wmealing/gleam-otp-design-principals/blob/main/gleam-otp-design-principals.org#starting-up-nodes https://github.com/wmealing/gleam-otp-design-principals/blob...
- victorbjorklund 2y agoThis is nice. Any way to also make it an Erlang complient node so it can be called from a erlang cluster?
- jerf 2y agoMaking something Erlang-compliant is actually fairly heavy duty. It's more than just "you've got actors, I've got actors, let's play together!"... you have to support the Erlang term format specifically, so on the Rust side you would need to be able to convert to and from all the state you actually want into Erlang terms, including PID references, you need to support Erlang's linking capability, you need to support Erlang's name server lookups, you need to support Erlang's specific messaging semantics for out-of-order message handling and mailboxes, binary sharing, probably some other things I'm not remembering. It's not an impossible amount of work but it's not in the "couple of weeks of spare time for a motivated developer" range either. Most people most of the time are just better hooking up one of the many, many other event busses that both Rust and Erlang can speak to and working across that.
- sph 2y agoNot only that, but you need a full BEAM-compatible VM, as you can send entire processes across nodes.
- throwawaymaths 2y agoNo, there are cnodes.
- snowboarder63 2y agoI actually have a side project doing this. I mapped an actor Id in ractor to a PID in erlang and used a rust create to implement the network protocol for erlang. I ran out of time on this side project kind of deal but it's like 90% there and can do a full cluster join and send and receive messages between remote actors on nodes. The crate that helped this is erl_dist. I'd love to open source the code at some point, but it's not quite there yet
- a-dub 2y agohow does it compare with bastion?
- rapsey 2y agoSorry for being so negative but why do people keep building these Actor frameworks for Rust? None of them get any usage.
- bowsamic 2y agoIt’s kind of like Java. It’s a way to feel like you’re doing work without actually doing anything
- rochak 2y agoCouldn’t have said it any better myself
- vdvsvwvwvwvwv 2y agoExcept it makes no sense. Java is a language that, while idiomatically a bit boilerplatey, is generally a workhorse for getting shit done.
- bowsamic 2y agoNo I mean in Java it’s common to write extensive boilerplate and abstractions just bc it feels constructive. Java is extremely useful, but business use of it is not so nice
- ahoka 2y agoIt’s everything but that. It’s the instrument of over engineering. Maybe not the language itself (it was the Rust if its time, everyone wanted to use it for everything, even if it made no sense), but the whole ecosystem just prefers complexity and breaking changes. Maybe it’s a coping mechanism for devs stuck with it, or I don’t know.
- Ygg2 2y ago> it's the instrument of over engineering. True, but find me one language that someone, somewhere didn't over- something. Either over-engineer or over-simplify, or over-use. People get excited about technology and try to push the envelope on its usage. That's true of any widely used tech. Hitting the golden middle is notoriously hard, especially when it is not the same middle for everyone. > the whole ecosystem What precisely do you mean? Sure Spring is notorious for this, but not the wider ecosystem. Sure some libraries might not be using SemVer, but Maven itself predates it as well.
- simonask 2y agoRactor is cool, but I've been wondering why it uses the async `async_trait` rather than native async traits. Is it just because it came out before async traits were stabilized, and now code relies on it and it would be a breaking change to migrate? For context, the `async_trait` crate makes futures from trait methods that are wrapped in `Pin<Box<dyn Future<...>>>`, which means that every async call to a trait method must make a heap allocation. This is currently a necessary thing to do if async trait methods were invoked with dynamic dispatch (through `dyn Actor`), but the `Actor` trait has associated methods, so that is already not generally possible. I realize that methods on the `Actor` trait return futures that are `Send`, but specifically for an actor framework that feels like a very specific design choice that isn't universally good or necessary. Another design would give let the spawned task that executes the actor's messages exclusive access to the actor (so `handle()` could take `&mut self`). I've ended up implementing a simple alternative design in my own project (it's not fundamentally very hard, but doesn't have all the features, like supervision) because the per-message heap allocations and internal locking became wasteful for my use case.
- SkiFire13 2y ago> I've been wondering why it uses the async `async_trait` rather than native async traits From their crate documentation[0]: > The minimum supported Rust version (MSRV) is 1.64. However if you disable the `async-trait` feature, then you need Rust >= 1.75 due to the native use of `async fn` in traits. [0]: https://docs.rs/ractor/0.13.0/ractor/index.html https://docs.rs/ractor/0.13.0/ractor/index.html
- k3vinw 2y agoThere’s also actix: https://github.com/actix/actix https://github.com/actix/actix
- lionkor 2y agoI use actix_web for all my web server stuff, its wonderful, super fast, really easy to use and not that easy to fuck up.
- hobofan 2y agoI know it seems unintuitive but actix-web is largely unrelated to actix nowadays: https://actix.rs/docs/whatis/ https://actix.rs/docs/whatis/
- deleted 2y ago[deleted]
- mtndew4brkfst 2y agoIt's been informally discouraged for use in net-new projects via a chat message from one of the maintainers during this year's RustConf. https://discord.com/channels/734893811884621927/1270439672627331202/1283493019403681814 https://discord.com/channels/734893811884621927/127043967262... Actix-web remains healthy in this regard, it was specifically just about the actix crate.
- Capricorn2481 2y agoThis link just goes to a blank discord page for me as if something is trying to load. I don't think these are shareable if you aren't in the server.
- qwertox 2y agoRelated from one month ago: Kameo - https://github.com/tqwewe/kameo https://github.com/tqwewe/kameo Show HN: Kameo – Fault-tolerant async actors built on Tokio - https://news.ycombinator.com/item?id=41723569 https://news.ycombinator.com/item?id=41723569 - October 2024 (58 comments)
- hit8run 2y agoWell someone got inspired by Rubys Ractors hence the naming? https://docs.ruby-lang.org/en/master/ractor_md.html https://docs.ruby-lang.org/en/master/ractor_md.html
- mtndew4brkfst 2y agoUnlikely, the contributors don't seem to have meaningful Ruby backgrounds. Isn't it a simpler supposition that the naming intent was merely (R)ust Actors?
- rubyfan 2y agoYeah bad choice of naming here. Oddly this project shows up first on DDG for “ractor” despite prevalent Ruby ractor documentation.
- nimchimpsky 2y ago[dead]
- pshc 2y agoI have to wonder if Ractor was inspired from The Diamond Age.
- zem 2y agowell, it's "r" + "actor" - just a coincidence that both "ruby" and "rust" started with an R!
- Sytten 2y agoI personnaly don't like the single enum model for messages. I prefer the generic Handler trait model. Also another square that I have not circled with async actor other than actix is that all of them use mutable self and they dont have a great way to have long running tasks. Sometimes you would want to call a remote server without blocking the actor, in actix this is easy to do and you unamed child actors to do that. All those newer frameworks don't have the primitives.
- ninkendo 2y agoAt $dayjob I've taken to just implementing my own actor-like model when I need interior mutability across tasks. Something like: struct State { counter: usize, control: mpsc::Receiver<Msg> } struct StateActor { addr: mpsc::Sender<Msg> } enum Msg { Increment { reply: oneshot::Sender<()> } } impl StateActor { pub async fn increment(&self) { let (tx, rx) = oneshot::channel(); let msg = Msg::Increment { reply: tx }; self.addr.send(msg).await.unwrap(); rx.await.unwrap(); } } impl State { fn start(self) { tokio::spawn(async move { /* ... tokio::select from self.control in a loop, handle messages, self is mutable */ /* e.g. self.counter +1 1; msg.reply.send(()) */ }) } } // in main some_state_actor.increment().await // doesn't return until the message is processed A StateActor can be cheaply cloned and used in multiple threads at once, and methods on it are sent as messages to the actual State object which loops waiting for messages. Shutdown can be sent as an in-band message or via a separate channel, etc. To me it's simpler than bringing in an entire actor framework, and it's especially useful if you already have control loops in your program (say, for periodic work), and want an easy system for sending messages to/from them. That is to say, if I used an existing actor framework, it solves the message sending/isolation part, but if I want to do my own explicit work inside the tokio::select loop that's not strictly actor message processing, I already have a natural place to do it.
- tel 2y agoI'm always most curious with these frameworks how they're considering supervision. That's the real superpower of OTP, especially over Rust. To me, Rust has adequate concurrency tooling to make ad hoc actor designs roughly on par with more developed ones for many tasks, but supervision is both highly valuable and non-trivial. Briefly, I'd say Rust is top-notch for lower-level concurrency primitives but lacks architectural guidance. Supervisor trees are a great choice here for many applications. I've tried implementing supervision a few times and the design is both subtle and easy to get wrong. Even emulating OTP, if you go that route, requires exploring lots of quiet corner cases that they handle. Reifying this all into a typed language is an additional challenge. I've found myself tending toward one_for_all strategies. A reusable Fn that takes some kind of supervisor context and builds a set of children, potentially recursively building the supervision tree beneath, tends to be the best design for typed channels. It forces one_for_all however as it's a monolithic restart function. You can achieve limited (batch-y) rest_for_one by having the last thing you boot in your one_for_all be another one_for_all supervisor, but this feels a little hacky and painful and pushes back against more granular rest_for_one designs. You then probably want a specialized supervisor for one_for_one, similar to Elixir's DynamicSupervisor.
- pton_xd 2y ago> That's the real superpower of OTP, especially over Rust. That, and preemptive scheduling. And being able to inspect / debug / modify a live system. Man, these actor frameworks just make me appreciate how cool Erlang is.
- 0x457 2y agoHere is how it explained in the docs: https://docs.rs/ractor/latest/ractor/actor/index.html#actor-supervision https://docs.rs/ractor/latest/ractor/actor/index.html#actor-...
- tel 2y agoIt's clear that there's some beginning of this in place. They reference it as initial in the docs there and it's missing quite a bit. I'm not a huge fan of what I'm seeing here where each actor is implicitly itself and a supervisor (i.e., ActorRef makes reference to the actor's children). I think I saw that first in Akka and while it makes sense in theory, I don't like the practice. To me, your supervision tree should be dedicated to that purpose and forms a superstructure relating entirely to spawning, resource provisioning, restarting, shutdown. Part of what makes it nice in Erlang is that it's consistent and thoughtless, just part of designing your system instead of being behavior you have to write or worry about much. Here with Ractor they've built a special monitoring channel and callbacks into Actor (`handle_supervisor_evt`). This implies at some point one might write a nice supervisor in their framework that hopefully has some of those properties.
- whytevuhuni 2y agoWhat's the benefit of having a State type, instead of using handle(&mut self), pre_start() -> Self, and putting the state inside the type that implements the actor?
- derefr 2y agoFrom the README (https://github.com/slawlor/ractor?tab=readme-ov-file#differences-between-an-actors-state-and-self https://github.com/slawlor/ractor?tab=readme-ov-file#differe...): > When designing ractor, we made the explicit decision to make a separate state type for an actor, rather than passing around a mutable self reference. The reason for this is that if we were to use a &mut self reference, creation + instantiation of the Self struct would be outside of the actor's specification (i.e. not in pre_start) and the safety it gives would be potentially lost, causing potential crashes in the caller when it maybe shouldn't. > Lastly is that we would need to change some of the ownership properties that ractor is currently based on to pass an owned self in each call, returning a Self reference which seems clunky in this context.
- slau 2y agoI’m not saying that you can’t use another project’s name, but there already exists an actor framework named Ractor, but this one written in Ruby. https://docs.ruby-lang.org/en/master/Ractor.html https://docs.ruby-lang.org/en/master/Ractor.html
- Alifatisk 2y agoI was about to mention this, Ractor is already a name used to describe the Ruby Actor class. But I guess this is only known within the Ruby Community? It would’ve taken one search to find out about this. Either way, since both names are bounded to their languages, the context should make it clear what is referred to. And to be fair, the name Ractor makes sense for both languages.
- snowboarder63 2y agoHonest truth? I didn't Google it first lol. I just checked if there was a crate with the same name and carried on. I only found out about the Ruby ones after I posted on Reddit for the first time. By then it was too late since I had already reserved the crate name and it was being downloaded
- samsartor 2y agoActors in Rust still kind of suck because there are no first-class resume arguments. In order to provide a `&mut State` you have to either: - handle messages sequentially per-actor (like Ractor, and like Bastion in practice) - create your own future trait without async/await (like Actix) I keep hoping the language team will get coroutines off the ground, but it hasn't happened yet.
- tel 2y agoWhat is a first-class resume argument? How does it enable &mut State and non-sequential messaging within Rust's current futures design?
- samsartor 2y agoRight now the only arguments to Future::poll are self and the task scheduler context. Any borrows of mutable state have to be captured by self, which means only one future with access to the state can be inflight at a time. If `&mut State` was an argument on resume, then the actor could schedule many futures simultaneously, which each getting temporary access to the state whenever it makes progress. Actix does exactly that, but it needs a bespoke ActorFuture trait with extra poll arguments. But until https://lang-team.rust-lang.org/design_notes/general_coroutines.html https://lang-team.rust-lang.org/design_notes/general_corouti... gets worked through, there is no way for actix to support async/await.
- tel 2y agoSo you're looking for a way for a future to make use of temporary access to state just while being polled? The issue being that since a future captures references in self you can't have multiple futures able to reference the same data via a &mut pointer. Instead you need to use Rc. If I'm understanding, then I don't yet follow the use case. You want to have multiple actors reading from the same message queue? Or different concurrent chunks inside of the actor? This feels to me to strain against the actor design pattern a lot. I feel this often, that futures are somewhat in tension with actors. There are too many options.
- webkike 2y agoI personally find actors in rust to be too much of a head ache. You might as well use Erlang (or elixir) and do your heaving lifting in rust with somethign like https://github.com/rusterlium/rustler https://github.com/rusterlium/rustler
- Fire-Dragon-DoL 2y agoMaybe a different name to avoid confusing with the ruby "actors"