tikv / grpc-rs

The gRPC library for Rust built on C Core library and futures
Apache License 2.0
1.81k stars 253 forks source link

grpc-rs doesn't compress response when client sent a compressed request #534

Closed lysu closed 3 years ago

lysu commented 3 years ago

tidb will use grpc to communicate with both tikv and other tidb.

when investigating an issue we found that only tidb->tidb got empty result due to https://github.com/grpc/grpc-go/issues/4552

but tikv works well, after more investigation it seems tikv server doesn't give a compressed response like grpc-go does, grpc-go seems response compressed data when client seen compressed data even if it doesn't enable compress in server-side.

I'm not sure is it a problem, ptal~

BusyJay commented 3 years ago

Can you provide a minimal reproduce example? Server won't compress response if the compression algorithm is not supported.

lysu commented 3 years ago

yes, we could use

https://github.com/lysu/grpc-go/blob/dev-test/examples/helloworld/greeter_client/main.go

as client...

and

https://github.com/tikv/grpc-rs/blob/fd66ec789b2601cd88f015fa4a33a6b5da431c11/tests-and-examples/examples/hello_world/server.rs

as server..

and check server response by set breakpoint on google.golang.org/grpc.recvAndDecompress at rpc_util.go:703, and watch pf var:

image

if server is rust, pf will be compressionNone... but compressionMade if we use go version https://github.com/lysu/grpc-go/blob/1ddc040f5c6c061b33331a50d6d08337e4a3e964/examples/helloworld/greeter_server/main.go

I also try to .default_compression_algorithm(CompressionAlgorithms::GRPC_COMPRESS_GZIP) in rust example, but it's still compressionNone

BusyJay commented 3 years ago

After commenting following line, the official cpp version of compression example also doesn't compress the response:

https://github.com/grpc/grpc/blob/master/examples/cpp/compression/greeter_server.cc#L44

It seems one has to set the compression type in server side to make it work. The cookbook https://github.com/grpc/grpc/blob/master/doc/compression_cookbook.md also doesn't have a clear statement that server response will use the same compression algorithm as client. The only one clear rule I can find is from go-grpc's documentation, which is a different implementation.

https://github.com/grpc/grpc-go/blob/master/Documentation/compression.md#server-side