|
|
%!s(int64=5) %!d(string=hai) anos | |
|---|---|---|
| .. | ||
| test | %!s(int64=5) %!d(string=hai) anos | |
| BUILD.bazel | %!s(int64=6) %!d(string=hai) anos | |
| README.md | %!s(int64=6) %!d(string=hai) anos | |
| client.py | %!s(int64=5) %!d(string=hai) anos | |
| server.py | %!s(int64=5) %!d(string=hai) anos | |
gRPC offers lossless compression options in order to decrease the number of bits transferred over the wire. Three levels of compression are available:
grpc.Compression.NoCompression - No compression is applied to the payload. (default)grpc.Compression.Deflate - The "Deflate" algorithm is applied to the payload.grpc.Compression.Gzip - The Gzip algorithm is applied to the payload.The default option on both clients and servers is grpc.Compression.NoCompression.
See the gRPC Compression Spec for more information.
Compression may be set at two levels on the client side.
with grpc.insecure_channel('foo.bar:1234', compression=grpc.Compression.Gzip) as channel:
use_channel(channel)
Setting the compression method at the call level will override any settings on the channel level.
stub = helloworld_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'),
compression=grpc.Compression.Deflate)
Additionally, compression may be set at two levels on the server side.
server = grpc.server(futures.ThreadPoolExecutor(),
compression=grpc.Compression.Gzip)
def SayHello(self, request, context):
context.set_response_compression(grpc.Compression.NoCompression)
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
Setting the compression method for an individual RPC will override any setting supplied at server creation time.