6

I am working on a grpc based application, where the request data could be up to 500KB and response could be bigger, and so I would like to compress the data. I have a hard time finding documents/examples in grpc on how to do it. What does set_compression_algorithm in clientContext do? Do I have to set up something on the server side?

Or should I instead forget about compression on grpc, and do compression/decompression into/out of protobuf messages myself?

4

1 回答 1

9

grpc::ClientContext::set_compression_algorithm方法选择用于客户端调用的算法,即从客户端发送到服务器的数据。

在服务器端,您可以通过(参见https://github.com/grpc/grpc/blob/master/include/grpc++/ server_builder.h),它允许您:grpc::ServerBuilder::SetCompressionOptions

  1. 选择服务器假定的压缩算法。默认情况下,启用所有算法。
  2. 选择默认情况下所有服务器响应将使用哪种压缩算法(如果对等客户端支持它。如果不支持,则响应将不压缩发送)。

对于服务器上的一次性呼叫响应,您可以使用grpc::ServerContext::set_compression_algorithmgrpc::ServerContext::set_compression_level。推荐使用后者,因为它会根据客户端保证支持的请求压缩级别选择最佳算法。

在接下来的几天里,我将整理出 hello-world 风格的示例。我创建了一个问题来跟踪此问题:https ://github.com/grpc/grpc/issues/6297 请随时在此处 ping。我还实现了一些低级日志记录以显示一些压缩统计信息,以便你们能够断言压缩实际上是有效的(否则一切都是完全透明的)。

于 2016-04-26T23:03:39.790 回答