[C++] Standalone example of mixing sync and async methods on a service?

880 views
Skip to first unread message

christop...@gmail.com

unread,
Oct 30, 2017, 8:01:33 PM10/30/17
to grpc.io
Are there any standalone examples of doing this for C++ servers?  This issue (https://github.com/grpc/grpc/issues/4285) points to test/cpp/end2end/hybrid_end2end_test.cc as examples of doing this.

My use case is a service comprised mostly of unary rpcs, but also supporting a server streaming rpc where one or more clients can register to receive future events from the server over a long-running connection.  
Was hoping to find an example that isn't as tightly coupled with the GRPC test framework.

Thanks in advance!

    Chris

aaj...@gmail.com

unread,
Feb 8, 2018, 9:58:22 AM2/8/18
to grpc.io
I too would be interested in a more straightforward example that isn't so tied to the GRPC test framework.

Also it would be helpful to understand the threading implications of a C++ service that mixes sync and async methods. My understanding is that a thread pool is provided for sync services but you have to provide your own threading model to wait on the completion queue for async services. What is the end result when a service mixes async and sync methods?

Vijay Pai

unread,
Apr 12, 2018, 2:36:58 PM4/12/18
to grpc.io
Hello there,
We don't have any examples right now outside of our tests, but let me respond to both questions here:

1. In the first case, why mix sync and async? In the C++ API both unary and streaming calls support sync or async APIs. That said, if you want to mark one of the methods async, just derive your service implementation from the WithAsyncMethod_METHODNAME version of the service. I agree that the code expansion can be ugly if we need to mark a lot of methods async.

2.  Yes, the sync API provides its own threadpool but you have to provide your own thread(s) for processing in the case of async. If a service mixes sync and async methods, gRPC's own threadpool will invoke the method handlers for the sync methods but you have to use your own thread(s) for processing the async methods.

Thanks and best regards!

-vjpai
Reply all
Reply to author
Forward
0 new messages