[C++] Is it possible to multi-thread asynchronous grpc server (By decoupling receiving and processing)?

Skip to first unread message

Jinkun Geng

Aug 9, 2022, 1:33:05 PMAug 9
to grpc.io
Hi, gRPC guys.
When I am studying the C++ APIs of gRPC, I have the following question about multi-threading on the server side:

Suppose I have a server, and there are many requests coming. Each request has a sequence number, and the server can only reply to the request with seq_no=n, after it has received all requests with seq_no <=n. But requests can come out of the seq_no order.  I do not want to block the receiving, so I have to find a way to decouple Receiving/Processing/Replying into independent threads:

Receive Request (1 Thread) --->  Process Thread (1 thread)  --> Send Response (1 Thread)

When a request is received by the Receiving thread, it can be passed to the Processing thread, and then it comes back to listen and receive other incoming requests. After the processing thread has confirmed that requests with seq_no=n is eligible to be responded, it can pass the information to the Response thread, and the Response thread can send the response.  

But when I checked the async example 

It still couples everything into one thread (HandleRPC).

Which only talks about parallelizing "Receive+Process+Response" as a whole, by using multiple completion queues. That does not fit my scenarios.

Therefore, I post this question to see whether some developers can give some hint. Or is this scenario not suitable to use gRPC?

Reply all
Reply to author
0 new messages