zoukankan      html  css  js  c++  java
  • grpc 使用压缩器 compressor wsarecv: An existing connection was forcibly closed by the remote host.

     wsarecv: An existing connection was forcibly closed by the remote host.

    优化方案:

    1)客户端连接复用

    2)压缩传输数据

     抓包分析,压缩前后数据字节数对比

    Basics tutorial | Go | gRPC https://grpc.io/docs/languages/go/basics/

    "google.golang.org/grpc"
    "google.golang.org/grpc/encoding/gzip"
    "google.golang.org/grpc/metadata"




    lis, err := net.Listen("tcp", port)
    if err != nil {

    }
    // TODO
    sp := keepalive.ServerParameters{
    MaxConnectionIdle: 128 * time.Second,
    MaxConnectionAge: 128 * time.Second,
    MaxConnectionAgeGrace: 128 * time.Second,
    Time: 128 * time.Second,
    Timeout: 128 * time.Second,
    }

    _defaultServerMaxReceiveMessageSize := 1024 * 1024 * 4 * 4

    so := grpc.MaxRecvMsgSize(_defaultServerMaxReceiveMessageSize)

    so1 := grpc.KeepaliveParams(sp)
    grpc.UseCompressor(gzip.Name)
    s := grpc.NewServer(so, so1)
    pb.RegisterCISServer(s, &server{})
    // ?? TODO
    reflection.Register(s)
    if err := s.Serve(lis); err != nil {
    }


    bytes := 1024 * 1024 * 4 * 4
    cp := grpc.ConnectParams{}
    cp.MinConnectTimeout = 16 * time.Second
    co := grpc.UseCompressor(gzip.Name)
    conn, err := grpc.Dial(conf.SrvAddr+":60053", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(bytes)),
    grpc.WithConnectParams(cp), grpc.WithDefaultCallOptions(co),
    )

  • 相关阅读:
    每天一个命令
    2017-2-21
    egrep []+ 和awk总结
    ifconfig eth0 取行取列
    stat /etc/hosts 取行取列644
    压缩解压缩
    目录
    公告
    To do list
    CSP 2019 游记
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15507428.html
Copyright © 2011-2022 走看看