--
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/99fcf2cf-e6e4-4918-8734-22b7f85cfb85n%40googlegroups.com.
I don't recommend using EzRPC. That interface turns out to be too restrictive.To set up a KJ event loop, use kj::setupAsyncIo().Then to initiate or accept Cap'n Proto RPC connections, use capnp::TwoPartyClient / capnp::TwoPartyServer.For FD passing, create a capnp server object that overrides the virtual method `kj::Maybe<int> Capability::Server::getFd()` to return an FD number. Then on the Client objects pointing to that server, you can call `getFd()` to get that file descriptor -- even from another process, as long as the connection between the two is a unix domain socket.-KentonOn Thu, May 6, 2021 at 1:07 PM pepijn de vos <pepij...@gmail.com> wrote:Thanks for the suggestions.This is still for the simulation server, so each connection is pretty expensive anyway, and it's unlikely there will be more in flight than the machine has cores available. It might even make sense to have a pool as you suggest, and just reject connections if there are no cores available. Concern is that you need to supervise these pools in case they crash. With fork you can just launch a new process. Any pointers to useful functions for this kinds of hacks would be appreciated. I don't have a clue how I'd go about obtaining and sending file descriptors over RPC and making new servers out of them. I should probably start by studying EzRPC and kj::LowLevelAsyncIoProvider.PepijnOn Thu, May 6, 2021 at 7:48 PM Kenton Varda <ken...@cloudflare.com> wrote:Ohhh, sorry, I misread. If you haven't started the KJ event loop until after the fork, you are probably OK.You can definitely construct a KJ socket from a raw socket using kj::LowLevelAsyncIoProvider.But if you're OK with the entire connection being handled in the isolated process, there are some other options too:- Have a pool of processes that are all waiting to accept from the same file descriptor. Each connection will only be accepted by one of the processes. Make sure that process doesn't accept a new connection until the old connection is done.- Cap'n Proto supports sending file descriptors between processes in RPC messages. So you could have one process that is accepting connections, but each time it does, it sends the file descriptor to some other processes via an RPC. Then that process actually handles the connection.These options are both more complicated than the simple fork() approach you mentioned, so aren't necessarily better. But fork() is pretty expensive so it might turn out reusing processes has some performance benefit.-KentonOn Thu, May 6, 2021 at 12:39 PM pepijn de vos <pepij...@gmail.com> wrote:Hi Kenton,Agree forking an eventloop will lead to disaster, which is why I suggested having a blocking accept loop, and then fork and start the event loop in the new process. But I'm not sure if it's at all possible to convert a raw unix socket to a jk socket and then give it to an eventloop to handle the connection.RPC to a process certainly requires less hacks.Pepijn