Capnproto RPC messaging with lockfree ring buffer between threads

58 views
Skip to first unread message

Ambrase

unread,
Jul 1, 2020, 12:47:14 PM7/1/20
to Cap'n Proto
Is it possible to use Capnproto RPC messaging to deliver function calls through lockfree ring buffer between threads?
There are 2 ring buffers (client -> server, server->client, 1 to many scenarios are also possible).
I'm thinking about how to use capnproto RPC messaging to pack a call to an object's interface from another thread and pass it through this interthread transport.
Any ideas or examples of how to approach this? Or Capnproto isn't suitable for such a task?

Many thanks

Kenton Varda

unread,
Jul 1, 2020, 1:24:41 PM7/1/20
to Ambrase, Cap'n Proto
Hi Dmitry,

You should be able to accomplish this by writing a custom implementation of VatNetwork. You can look at TwoPartyVatNetwork for an example.

That said, if you're thinking about optimizations like lock-free ring buffers, you may find that the RPC system itself adds too much overhead for your use case, due to the bookkeeping it does that is primarily designed to compensate for latency over a network -- which you don't really have. It might make more sense to use Cap'n Proto's serialization layer directly and implement your own work queue around that.

-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/ca16c240-365a-4f53-ab73-552b175a444eo%40googlegroups.com.

Ambrase

unread,
Jul 1, 2020, 2:04:38 PM7/1/20
to Cap'n Proto
Is it possible to use interfaces in messages detached from all other RPC code like TwoPartyVatNetwork ?

For example, write down an Interface {...} in a scheme matching to the interface of the actual class that will be called, generate code with capnp and use the resulted client and server in 2 different threads just to serialize and dispatch requests/responses?
Or, can I only do this with usual capnp messaging? Create a usual message with a code for a specific function that should be called and some sort of generic scheme for parameters pack.

Thanks


On Wednesday, July 1, 2020 at 8:24:41 PM UTC+3, Kenton Varda wrote:
Hi Dmitry,

You should be able to accomplish this by writing a custom implementation of VatNetwork. You can look at TwoPartyVatNetwork for an example.

That said, if you're thinking about optimizations like lock-free ring buffers, you may find that the RPC system itself adds too much overhead for your use case, due to the bookkeeping it does that is primarily designed to compensate for latency over a network -- which you don't really have. It might make more sense to use Cap'n Proto's serialization layer directly and implement your own work queue around that.

-Kenton

On Wed, Jul 1, 2020 at 11:47 AM Ambrase <ambr...@gmail.com> wrote:
Is it possible to use Capnproto RPC messaging to deliver function calls through lockfree ring buffer between threads?
There are 2 ring buffers (client -> server, server->client, 1 to many scenarios are also possible).
I'm thinking about how to use capnproto RPC messaging to pack a call to an object's interface from another thread and pass it through this interthread transport.
Any ideas or examples of how to approach this? Or Capnproto isn't suitable for such a task?

Many thanks

--
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 capn...@googlegroups.com.

Kenton Varda

unread,
Jul 1, 2020, 2:19:58 PM7/1/20
to Ambrase, Cap'n Proto
In fact, it is technically possible to use interfaces independently of the RPC system. Study capnp/capability.h to see the interfaces you'd need to define.

However, I guess you'd end up repeating a lot of the work of the RPC implementation. So I don't recommend that. I guess it probably makes the most sense to implement VatNetwork and see if the performance meets your needs. If not, there may be some easy optimization opportunities to solve that, and if that doesn't work either, then you could think about implementing the capability hook interfaces directly as a further optimization.

-Kenton

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/fccb2c61-8094-4858-97ae-7235b194ff19o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages