Enabling a Capnp Server to accept parallel requests #1958
-
Hello there,
I notice that I am not getting the requests parallely in my capnp server.It seems that only after a request has been processed by the server, I am getting the next request.So I assume the requests are getting somewhere queued in between capnp client and server. Does capnp internally queues the requests? I want to understand how can I modify my code so that my server can accept parallel requests that the client can make.Any help would be appreciated :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Cap'n Proto uses event loop concurrency. You need to use the KJ event loop and Promises to perform any work asynchronously, so that other requests are allowed to arrive in the meantime. See: https://github.com/capnproto/capnproto/blob/v2/kjdoc/tour.md#asynchronous-event-loop In your code, you attempt to create two threads that wait on the same socket. The second thread probably fails with an "address in use" error. Only one thread can be listening on a socket at a time. |
Beta Was this translation helpful? Give feedback.
GetAutocompleteSuggestions
would need to use KJ promises internally for any I/O it performs, in order to yield to the event loop while it waits.Alternatively, you could use
newPromiseAndCrossThreadFulfiller
, and then haveGetAutocompleteSuggestions
run in a separate thread.