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

  • 相关阅读:
    IntelliJ IDEA 14.03 java 中文文本处理中的编码格式设置
    应聘感悟
    STL string分析
    CUDA SDK VolumeRender 分析 (1)
    BSP
    CUDA SDK VolumeRender 分析 (3)
    CUDA SDK VolumeRender 分析 (2)
    Windows软件发布时遇到的一些问题
    Ten Commandments of Egoless Programming (转载)
    复习下光照知识
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15507428.html
Copyright © 2011-2022 走看看