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),
    )

  • 相关阅读:
    python 代码片段8
    python 代码片段7
    python 代码片段6
    python 代码片段5
    python 代码片段4
    django 代码片段3
    python 代码片段2
    Redis事物
    Redis的java客户端jedis
    Redis五大数据类型
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15507428.html
Copyright © 2011-2022 走看看