what's mean about "threads are encouraged to communicate through Cap’n Proto RPC"

55 views
Skip to first unread message

YY Dragon

unread,
May 20, 2020, 3:54:09 AM5/20/20
to Cap'n Proto
as https://capnproto.org/cxxrpc.html say KJ discourages fine-grained interaction between threads as synchronization is expensive and error-prone. Instead, threads are encouraged to communicate through Cap’n Proto RPC. 
I have question , how can I ues rpc for threads communicate?
should I instantiate a capnp::EzRpcServer on each thread?

Kenton Varda

unread,
May 21, 2020, 10:39:02 AM5/21/20
to YY Dragon, Cap'n Proto
That would be one way to do it. Make sure to use Unix sockets as they are much more efficient than TCP.

That said, writing the messages out to a socket and reading it back in is still a bit silly for inter-thread communication, where the target thread could just read the message from memory. Unfortunately the capnp library doesn't currently include code for efficient inter-thread RPC. I've been meaning to write a new implementation of VatNetwork using kj::Executor for inter-thread comms but haven't had the chance yet.

So for now, what I'd actually recommend for inter-thread communications is to use kj::Executor directly. This lets you run an arbitrary lambda on another thread and have the result sent back to the calling thread.

Probably I should update the doc to not suggest inter-thread RPC until it's actually implemented... :)

-Kenton

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/8a3a68cb-7a4d-45e0-b7c6-2a7456d34a91%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages