Tradias/asio-grpc

Design help with io_context and agrpc::GrpcContext

bharat76 opened this issue · 3 comments

Hello @Tradias, I was following the examples in asio-grpc/examples (share-io-context-server.cpp)

Is there a way to use agrpc::GrpcContext rather than io_context in my application (does grpc allow that)?
Or can a grpc_context be constructed with io_context?
The explicit io_context is not that clear from documented link.

I need to try other experiments to confirm this.
Thanks @Tradias

Ok, I am very interested in making the documentation around the use of io_context+asio-grpc as clear as possible, as this is one of the most frequently asked questions. If you have any suggestions for improvements then please let me know.

Also note that this issue (#65) revealed that when using agrpc::run(grpc_context, io_context) with a stopped GrpcContext (for example because it ran out of work) and a running io_context, the CPU consumption shoots to 100%. Just in case you experimenting with that.

Something you might like consider.

  1. The example on link is client specific. A server code snippet might be helpful as well. share-io-context-server.cpp is an example, though in source tree.
// First, initiate the io_context's thread_local variables by posting on it. The io_context uses them to optimize dynamic memory allocations.

is bit difficult comprehend.

  1. Do we need post? Was post part of fix on 65
               [&]
               {
                   io_context.get_executor().on_work_finished();
                   [agrpc::run](https://tradias.github.io/asio-grpc/namespaceagrpc.html#ab52a5b6f6ce90d1bc9faa5baa96a39fa)(grpc_context, io_context);
                   io_context.get_executor().on_work_started();
               });