Uses Handler trait instead of Actor trait to define possible messages #88
Replies: 11 comments
-
So I'll have to look more into how Also does a I guess you could just not await the future, but that seems wrong than explicitly sending a 1-way message.... And if you await the reply always, you can (1) get deadlocks without realizing pretty easily (A triggers B, and waits on B's reply which requires pinging A. If A waits on the initial send to B, deadlock) and (2) If the actor has a long message queue, that await might take a long time to return when you don't need to process a result. |
Beta Was this translation helpful? Give feedback.
-
Yeah, they do. You just add a handler per message type. I have a few ideas for "no reply". The simplest would be to make the response a Maybe two handlers, one with response, one without? I think it might even be better to make handlers return nothing. If you need a response, you could then send a channel or something similar, which the handler uses to send something back. Then you could probably build convenience wrappers that work with return types, but use the primitives that already exist. Maybe there is some inspiration to be had from CAF. |
Beta Was this translation helpful? Give feedback.
-
Hmm this might be tricky for the cluster scenario. You'd need to know each message type and still be able to multiplex around them in order to send the right message over the link. Even from the It looks like CAF has network communication support, but I'll need to read more to see what the implications might be doing this. |
Beta Was this translation helpful? Give feedback.
-
Ah so I played around a tiny bit and it's more difficult than I originally thought for more basic reasons. You have the basic Either that, or the base actor trait would need to know all the message types it supports, which imo defeats the purpose of having the I'll keep this idea in mind, but I'm not sure (right now) if it'll fit into how we structured things. Thanks for the suggestion though! |
Beta Was this translation helpful? Give feedback.
-
Depending on how strongly typed everything is, it might be possible to send a message to an actor that doesn't support it. In this case, the actor would probably answer with something along the lines of I'm not too into the details of ractor, so I can't speak on whats possible now and what should/will be possible in the future, so this might never come up anyway, but being able to send untyped messages to actors might still be something to consider for building generic fan-out actors or similar. I'm currently a bit sick, but I might have a look at the internals of ractor to see if it could be incorporated somehow. |
Beta Was this translation helpful? Give feedback.
-
CAF has network support, because every message must be serializable. So if you cross that border, it gets serialized and deserialized on the other side. But because it's C++, you can probably do some crazy tricks to see which messages have appropriate handlers. |
Beta Was this translation helpful? Give feedback.
-
Yeah we do a similar thing, but you can opt-in to serializability in |
Beta Was this translation helpful? Give feedback.
-
I think having serializability as requirement would still be a big benefit, as you get location transparency for free. If every message is serializable, you don't need to think about which actor is on the same platform and which isn't. And you can move actors from local to remote without changing anything. |
Beta Was this translation helpful? Give feedback.
-
The way it's designed here, you don't need to think about which actor is where. If a actor is remote or local is completely transparent to the actor. The point of making it opt-in, is serializability isn't a trivial definition in some Rust structs (like discriminated union/enums). Additionally it allows you to be specific about some things, like serializing a However, once defined, if the actor is local or remote doesn't matter to all of the APIs and it's completely seemless. Actors which don't support remote-calling would just not be represented across the remote link in the remote |
Beta Was this translation helpful? Give feedback.
-
So, because there are platform specific concerns that one has to think about anyway, serialization is not required by default as it may hide those problems in trivial scenarios. Makes sense to me. IIRC in CAF the requirements for messages are:
Here's the description from CAF:
They even advice on only using fixed size ints in order to not get weird behavior in homogeneous environments. This could probably be handled by a custom They even have an unsafe message type, which does not need to be serializable, but will fail compilation if you try to send those over the network. After reading through all this, I think defining a trait would be a good way forward, as it allows to the types that can be sent over the network, because, as you said, some types like usize might be valid for serialization, but not for sending to actors on different platforms. This would allow for more fine grained control and could, combined with a derive macro, be used quite easily as well. |
Beta Was this translation helpful? Give feedback.
-
I quite agree with all the points mentioned by @hardliner66. Having a I understand there's some issues with serialization and distributed clustering, but if those could somehow be resolved that would be amazing! |
Beta Was this translation helpful? Give feedback.
-
One of the things I like about actix, is the possibility to define handlers for multiple messages per actor, which is something that erlang, caf and akka (iirc) allow as well. I know that this can be emulated with enums, but having it work without would be a good quality of life improvement.
Actix Example:
Beta Was this translation helpful? Give feedback.
All reactions