Is it possible to enable GRPC message compression in server? (Python)

[亡魂溺海] 提交于 2020-01-06 06:57:48

问题


I have a gRPC client (in Java) sending requests to a server (written in Python). I need to enable both request compression and response compression. There is good documentation on how to enable compression on the client side. I have managed to compress the request like so:

 response = blockingStub.withCompression("gzip").method(request)

However, I cannot find any documentation on how to compress the server response (also). It seems that there is almost no documentation (or examples) on how to use gRPC message compression in Python. How can I enable server-side compression? The call is a simple RPC call (no streaming).


回答1:


Compression in Python is supported via metadata arguments.

You can find an example here: https://github.com/grpc/grpc/blob/master/src/python/grpcio_tests/tests/unit/_compression_test.py




回答2:


To add to kpayson64's answer which covers call-level compression, you can set compression settings on a grpc.Channel or grpc.Server object upon initialization via the channel arg grpc.default_compression_algorithm.

Please also see the gRPC Compression Cookbook on recommendations on where to or not to explicitly enable compression.



来源:https://stackoverflow.com/questions/50509606/is-it-possible-to-enable-grpc-message-compression-in-server-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!