0

Is there any way to enable compression in a grpc-nodejs server?

It seems that it's possible to implement it, since it can deflate/unzip compressed data, but cannot compress while sending the response back.

I spun up the test nodejs server, and interacted with it using a python client. I MITM-ed the interaction between the server and client using nc to get the number of bytes transferred, and see the effect of compression.

When I sent the 'grpc.default_compression_algorithm' metadata while making the request through the python client, I was able to see that the data sent by the client was compressed, but the data sent back by the server was uncompressed. (sent 815, rcvd 300324 for an echo grpc service).

Setting metadata on the nodejs server side doesn't help, it still sends uncompressed data.

The reason why I think this should be possible is because it was able to read the compressed request. Also the npm grpc package is a wrapper over a grpc binary. Running an nm grpc_node.node | grep gzip returns

0000000000306800 d grpc_stream_compression_gzip_vtable
00000000000b2fd0 t _ZL10gzip_flateP36grpc_stream_compression_context_gzipP17grpc_slice_bufferS2_PmmiPb
00000000000b3670 t _ZL25grpc_stream_compress_gzipP31grpc_stream_compression_contextP17grpc_slice_bufferS2_Pmm29grpc_stream_compression_flush
00000000000b3600 t _ZL27grpc_stream_decompress_gzipP31grpc_stream_compression_contextP17grpc_slice_bufferS2_PmmPb
00000000000b2ed0 t _ZL43grpc_stream_compression_context_create_gzip30grpc_stream_compression_method
00000000000b2e70 t _ZL44grpc_stream_compression_context_destroy_gzipP31grpc_stream_compression_context
4

1 回答 1

0

设置这个对我有用。

let server = new grpc.Server({
    'grpc.default_compression_level': 2, // (1->Low -- 3->High)
});
于 2018-07-31T07:10:49.833 回答