when I start 1600 rpc clients to request an rpc server concurrently. Only about 100 Clinets can request successfully, and the rest report the following error: rpc error: code = Unavailable desc = connection closed before server preface received
this is my code
init the client
var (
threads = 1600
reqlength = 122
port = 8011
)
func (this *RpcClient) init(addr string) bool {
this._p_addr = &addr
//maxSize := 300 * 1024 * 1024
//diaOpt := grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxSize), grpc.MaxCallSendMsgSize(maxSize))
conn, err := grpc.Dial(*this._p_addr, grpc.WithInsecure())
if err != nil {
fmt.Printf("node server cli, dia server %s failed: %v", addr, err)
return false
}
this._conn = conn
this._client = pb.NewTestQPSClient(conn)
if this._client == nil {
fmt.Printf("node server cli init connect failed %s", addr)
return false
}
return true
}
create 1600 clients and request the rpc server concurrently
func main() {
fmt.Printf("start client with %d threads size %d\n", threads, reqlength)
//_cli := RpcClient{}
//_cli.init("localhost:8010")
wg := sync.WaitGroup{}
for j := 0; j < threads; j++ {
wg.Add(1)
go func(x int) {
defer wg.Done()
_cli := RpcClient{}
_cli.init(fmt.Sprintf("127.0.0.1:%d", port))
buf := make([]byte, reqlength)
//for {
req := pb.Req{}
//rand.Read(buf)
req.ReqData = buf
_, err := _cli._client.LoadData(context.Background(), &req)
if err != nil {
fmt.Println(err.Error())
return
}
//}
}(j)
}
wg.Wait()
}
I got the error:
rpc error: code = Unavailable desc = connection closed before server preface received
rpc error: code = Unavailable desc = connection closed before server preface received
......
rpc error: code = Unavailable desc = connection closed before server preface received
rpc error: code = Unavailable desc = connection closed before server preface received