https://github.com/grpc/grpc/blob/master/examples/cpp/helloworld/greeter_async_server.cc#L91
service_->RequestSayHello(&ctx_, &request_, &responder_, cq_, cq_,
this);
这两次出现的cq_
对我来说很奇怪,所以我深入研究了源代码,它引导我
https://github.com/grpc/grpc/blob/master/include/grpcpp/impl/codegen/service_type.h#L92
void RequestAsyncUnary(int index, ServerContext* context, Message* request,
internal::ServerAsyncStreamingInterface* stream,
CompletionQueue* call_cq,
ServerCompletionQueue* notification_cq, void* tag) {
server_->RequestAsyncCall(methods_[index].get(), context, stream, call_cq,
notification_cq, tag, request);
}
那么call_cq
和notification_cq
有什么不同呢?使用差异完成队列的潜在用途/好处是什么?
发布于 2019-04-01 02:21:35
当同样的问题被问到时,这里引用了grpc的google-groups论坛的一句话。https://groups.google.com/forum/#!topic/grpc-io/V4NAQ77PMEo
Notification_cq将取回指示呼叫已开始的标记。对该调用的所有后续操作(读取、写入等)都会报告回call_cq。对于大多数异步服务器,我的建议是使用相同的cq。你可能不会去的地方:
这允许细粒度地控制哪些线程处理哪些类型的事件(基于它们正在轮询的队列)。例如,您可能有一个主线程轮询notification_cq,而工作线程轮询它们自己的call_cqs,或者类似的东西。
https://stackoverflow.com/questions/51435147
复制相似问题