简体   繁体   English

gRPC - 累积来自多个客户端的请求

[英]gRPC - Accumulate requests from Multiple clients

Let's assume I have multiple clients sending requests to a server (gRPC service).假设我有多个客户端向服务器(gRPC 服务)发送请求。 I would like my server to be able to collect, let say 8 requests, process these requests at once, and then only send the result back to the clients.我希望我的服务器能够收集,比如说 8 个请求,一次处理这些请求,然后只将结果发送回客户端。 I'm not sure how to do this using GRPC functionalities, or even if it's possible or if I need something else.我不确定如何使用 GRPC 功能来做到这一点,或者即使可能或我是否需要其他东西。

context: my use case comes from serving a neural network which is on GPU.上下文:我的用例来自为 GPU 上的神经网络提供服务。 In this case, it's much more efficient to batch the input of multiple requests, do one inference, and send the result back rather than do one inference per input.在这种情况下,批处理多个请求的输入,进行一次推理,然后将结果发回,而不是对每个输入进行一次推理,效率要高得多。

At least 3 options.至少3个选项。 Here in order of increasing complexity:这里按复杂性增加的顺序:

  1. Clients make calls to the server with their data.客户端使用他们的数据调用服务器。 The server responds with a batch number.服务器以批号响应。 Clients then use the batch number to make a "Done yet?"客户然后使用批号做出“完成了吗?” RPC against the server.针对服务器的 RPC。 The simplest approach but uses polling and is more wasteful.最简单的方法,但使用轮询并且更浪费。

  2. Clients make calls to the server with their data.客户端使用他们的数据调用服务器。 The server responds with a stream of messages updating the client on the batch's state .... working, working, working, done [results].服务器响应消息流更新客户端的批处理状态......工作,工作,工作,完成[结果]。 The advantage is the implicit 'callback' made explicit in #3 below.优点是隐含的“回调”在下面的#3 中明确表示。 The disadvantage is the redundancy of the stream if you're less concerned about intermediate states.如果您不太关心中间状态,则缺点是流的冗余。

  3. Clients make calls to the server with their data and a callback address.客户端使用他们的数据和回调地址调用服务器。 The server (as a gRPC client) uses the callback to make an RPC on the client (operating as a gRPC server).服务器(作为 gRPC 客户端)使用回调在客户端(作为 gRPC 服务器操作)上进行 RPC。 Most complex and likely unnecessarily so given #1 & #2.最复杂且可能是不必要的,因此给出 #1 和 #2。

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

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