【问题标题】:Enable compression in nodejs grpc server在 nodejs grpc 服务器中启用压缩
【发布时间】:2018-12-31 01:09:29
【问题描述】:

有没有办法在 grpc-nodejs 服务器中启用压缩?

似乎可以实现它,因为它可以对压缩数据进行放气/解压缩,但在发送回响应时无法压缩。

我启动了测试 nodejs 服务器,并使用 python 客户端与之交互。我用nc MITM-ed服务端和客户端的交互,得到传输的字节数,看看压缩的效果。

当我通过python客户端发出请求时发送'grpc.default_compression_algorithm'元数据时,我能够看到客户端发送的数据是压缩的,但服务器发回的数据是未压缩的。 (sent 815, rcvd 300324 用于 echo grpc 服务)。

在 nodejs 服务器端设置元数据没有帮助,它仍然发送未压缩的数据。

我认为这应该是可能的原因是因为它能够读取压缩请求。此外,npm grpc 包是 grpc 二进制文件的包装器。运行nm grpc_node.node | grep gzip 返回

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

【问题讨论】:

    标签: node.js protocol-buffers grpc grpc-node


    【解决方案1】:

    设置这个对我有用。

    let server = new grpc.Server({
        'grpc.default_compression_level': 2, // (1->Low -- 3->High)
    });
    

    【讨论】:

      猜你喜欢
      • 2018-11-03
      • 1970-01-01
      • 2011-10-23
      • 1970-01-01
      • 2023-03-23
      • 2020-07-07
      • 2011-03-10
      • 2012-09-01
      • 1970-01-01
      相关资源
      最近更新 更多