[Question] How to send big data using the messaging system of actor?
Hi, I am new to the actor-based system. This is my first time to use the actor framework. And I really like riker. It is well-documented and elegant.
But, I ran into a serious issue several days ago and I don't know how to solve it.
How can I send big messages between actors? If I send the messages between actors, I have to derive Clone and Copy traits for the data structs which I used for wrapping messages. Clone is so a big issue to ignore, especially for big messages.
For example, I have a receiver actor for receiving TcpStream. Then the receiver actor processes it, stores some necessary information, and then pass it to the next actor for future processing.
It simply acts like this:
Big Big TcpStream --> receiver actor --> Big big struct (converted from receiver actor) --> A actor (recording some basic info) --> B actor (processes it, or stores it) --> End
So, in my opinion, it is not a good idea to pass big data struct around between actors. It could impact the performance greatly possibly. Maybe is it not a good idea to use an actor-based framework? Maybe I should just stick to the traditional threading methods?
Or, is it possible to pass the reference to that big data struct between actors? (maybe use a pool or something?)
PS:
- I know this issue is not highly related to the
rikeritself. But it would be extremely helpful to point out something for me. - Are there some projects using
rikerright now? It will be really nice for me to imitate those codes. (Maybe it is also really nice for a newbie, like me.)
I think we should try to get rid of the Clone requirement. There should be no need to clone a Message. Moving it around is definitely a bit harder, but it should work.
In the meantime you could try the following:
Instead of passing the data directly, you can wrap it into an Arc. This way only the Arc gets cloned, which should be way cheaper.
@hardliner66 Thanks for your advice. I will try to wrap big struct to Arc.