简体   繁体   English

grpc 库是否支持阻塞来自完成队列的 n 个事件的完成状态?

[英]Does the grpc library support blocking on the completion status of n events from completion queue?

We make multiple asynchronous requests in parallel with a unique tag for each.我们并行地发出多个异步请求,每个请求都有一个唯一的标签。 We want to block and wait until all those events have completed with success, failure, or have timed out.我们想要阻止并等待所有这些事件以成功、失败或超时的方式完成。

We can accomplish this by counting the total number of outstanding calls and decrementing the total in-flight by 1 each time an event is popped off of the queue.我们可以通过计算未完成呼叫的总数并在每次事件从队列中弹出时将飞行中的总数减 1 来完成此操作。 I really don't like this.我真的不喜欢这个。

  1. This requires that the completion queue is either instantiated on a per-call basis (this has considerable overhead) or that we re-use a queue but ensure that there is only 1 active user of the queue at a given time.这要求完成队列要么在每次调用的基础上实例化(这有相当大的开销),要么我们重新使用队列但确保在给定时间队列中只有 1 个活动用户。 That means for m threads making n calls, we need m queues each servicing n calls.这意味着对于进行 n 个调用的 m 个线程,我们需要 m 个队列,每个队列为 n 个调用提供服务。

  2. We decrement in-flight on the assumption that no other events will come from the queue.我们在假设没有其他事件来自队列的情况下减少飞行中。 I don't know if this is a guarantee.我不知道这是否是一种保证。

     int inFlight = 10; // eg with dummy data while(cq->Next(&tag, &ok) { inFlight--; if (inFlight == 0) break; /// process... }

Is there a way to block and wait for n tagged async events to finish that is supported by the library?有没有一种方法可以阻止并等待库支持的 n 个标记的异步事件完成?

Is it possible to block and wait for these events while the queue is being multiplexed?是否可以在多路复用队列时阻塞并等待这些事件?

gRPC doesn't have the mechanism to support your case. gRPC 没有支持您的案例的机制。 Completion queue is a low-level component which handles async operations so it mainly works as a simple queue.完成队列是处理异步操作的低级组件,因此它主要用作简单队列。 So you might have to manage its own way to do a bookkeeping.所以你可能必须管理自己的方式来做簿记。 ClientInterceptor might be helpful to do the same thing across different rpcs. ClientInterceptor可能有助于跨不同的 rpc 执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM