gpt4 book ai didi

grpc - gRPC 中的 call_cq 和 notification_cq 有什么区别?

转载 作者:行者123 更新时间:2023-12-03 16:14:27 25 4
gpt4 key购买 nike

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 ?使用差异完成队列的潜在用途/好处是什么?

最佳答案

当提出同样的问题时,这是来自 grpc 的 google-groups 论坛的引述。
https://groups.google.com/forum/#!topic/grpc-io/V4NAQ77PMEo

Notification_cq gets the tag back indicating a call has started. All subsequent operations (reads, writes, etc) on that call report back to call_cq. For most async servers my recommendation is to use the same cq. Places where you might not:

  1. Our sync API creates a cq per call under the covers... So it posts a general event >queue for notification_cq, and it's specific queue as call_cq.
  2. If you want to be able to control when you accept incoming calls vs when you don't (by suspending polling on a notification_cq)
  3. I'm sure folks can think of others.


这允许细粒度控制哪些线程处理哪些类型的事件(基于它们正在轮询的队列)。就像您可能有一个主线程轮询 notification_cq 和所有工作线程都轮询他们自己的 call_cqs 或类似的东西。

关于grpc - gRPC 中的 call_cq 和 notification_cq 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51435147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com