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