Re: [capnproto] Multiple server threads on same port

2022-07-02 Thread 'Peter Goodman' via Cap'n Proto
Thank you! I will look into this and get back to you; I'm probably going to
have questions. Do you know of any open-source projects doing something
like this, so that I can see how they used the underlying / relevant kj
APIs?

On Wed, Jun 29, 2022 at 3:54 PM Kenton Varda  wrote:

> Hi Peter,
>
> Blocking the event loop may cause a bunch of subtle problems. It may be
> possible to get away with if your RPC protocol is incredibly simple
> (request/response with one request at a time), but if you do anything more
> advanced with Cap'n Proto you'll run into problems. Cap'n Proto was
> designed to allow multiple RPCs at the same time, RPCs in both directions,
> etc.
>
> If you have to call into a library that only offers a blocking interface,
> I would probably recommend calling it from a separate thread. Of course,
> that means you need some way to signal between threads, which is a pain.
> You may end up needing to use the lower-level KJ async I/O APIs. I would
> avoid EzRpcServer which hides too much of the functionality that KJ offers.
>
> It is also possible to use multiple threads. Again this is easiest if you
> use the low-level KJ I/O APIs. If you're doing one thread per connection,
> it might make sense to just have the thread do an old fashion blocking
> accept() call on the listen socket, then run that connection to completion,
> then go back and do accept() again. The listen socket itself would be an FD
> shared across all threads, so you wouldn't want to use the KJ wrappers for
> that.
>
> -Kenton
>
> On Wed, Jun 29, 2022 at 2:33 PM 'Peter Goodman' via Cap'n Proto <
> capnproto@googlegroups.com> wrote:
>
>> My current situation is that I have many concurrent clients initiating
>> RPCs to a server, and the implementation of these RPCs on the server blocks
>> (calls to external APIs). What is the best practice way of handling this
>> with Cap'n Proto? Should I run the blocking code on separate threads, and
>> have them signal the EzRpcServer server thread somehow? Should I (and can
>> I) run multiple EzRpcServer threads, each connecting to the same host:port?
>> Or both?
>>
>> Thank you for any possible recommendations.
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/capnproto/7e39d599-45f9-4208-9c89-6e6996d231een%40googlegroups.com
>> 
>> .
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAN5UQN7y5m90-g3QwT38yzEZfRSVBJQityT76AxEAhmWtX0OgQ%40mail.gmail.com.


Re: [capnproto] Multiple server threads on same port

2022-06-29 Thread 'Kenton Varda' via Cap'n Proto
Hi Peter,

Blocking the event loop may cause a bunch of subtle problems. It may be
possible to get away with if your RPC protocol is incredibly simple
(request/response with one request at a time), but if you do anything more
advanced with Cap'n Proto you'll run into problems. Cap'n Proto was
designed to allow multiple RPCs at the same time, RPCs in both directions,
etc.

If you have to call into a library that only offers a blocking interface, I
would probably recommend calling it from a separate thread. Of course, that
means you need some way to signal between threads, which is a pain. You may
end up needing to use the lower-level KJ async I/O APIs. I would avoid
EzRpcServer which hides too much of the functionality that KJ offers.

It is also possible to use multiple threads. Again this is easiest if you
use the low-level KJ I/O APIs. If you're doing one thread per connection,
it might make sense to just have the thread do an old fashion blocking
accept() call on the listen socket, then run that connection to completion,
then go back and do accept() again. The listen socket itself would be an FD
shared across all threads, so you wouldn't want to use the KJ wrappers for
that.

-Kenton

On Wed, Jun 29, 2022 at 2:33 PM 'Peter Goodman' via Cap'n Proto <
capnproto@googlegroups.com> wrote:

> My current situation is that I have many concurrent clients initiating
> RPCs to a server, and the implementation of these RPCs on the server blocks
> (calls to external APIs). What is the best practice way of handling this
> with Cap'n Proto? Should I run the blocking code on separate threads, and
> have them signal the EzRpcServer server thread somehow? Should I (and can
> I) run multiple EzRpcServer threads, each connecting to the same host:port?
> Or both?
>
> Thank you for any possible recommendations.
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/7e39d599-45f9-4208-9c89-6e6996d231een%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQk8ywge9qKzr0mCovA8y5gzEOpyp4a2JE9fNhFmFg2BnQ%40mail.gmail.com.


[capnproto] Multiple server threads on same port

2022-06-29 Thread 'Peter Goodman' via Cap'n Proto
My current situation is that I have many concurrent clients initiating RPCs 
to a server, and the implementation of these RPCs on the server blocks 
(calls to external APIs). What is the best practice way of handling this 
with Cap'n Proto? Should I run the blocking code on separate threads, and 
have them signal the EzRpcServer server thread somehow? Should I (and can 
I) run multiple EzRpcServer threads, each connecting to the same host:port? 
Or both?

Thank you for any possible recommendations.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/7e39d599-45f9-4208-9c89-6e6996d231een%40googlegroups.com.