Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating receive and send message size for grpc in golang

Tags:

go

grpc

I have grpc server written in Go and I am trying to update receive and send message size to 20MB instead of the default 4MB with the following code

var s *grpc.Server
s = grpc.NewServer(grpc.MaxRecvMsgSize(1024*1024*20), grpc.MaxSendMsgSize(1024*1024*20))

pb.RegisterProductServer(s,mysrv)

But the above doesn't seem to be working as I still get an error when I tried to call from a client received message larger than max (5807570 vs. 4194304)" Not sure whats overriding the size

like image 316
DoIt Avatar asked Jan 10 '19 22:01

DoIt


1 Answers

I haven't had the chance to test this yet but have you tried adding the same options from the client stub? The same options can be attached as dial options:

maxMsgSize := 1024*1024*20
conn, err := grpc.Dial(address, grpc.WithDefaultCallOptions(grpc.MaxRecvMsgSize(maxMsgSize), grpc.MaxSendMsgSize(maxMsgSize)))
if err != nil {
    // ...
}
defer conn.close()
client := pb.NewProductClient(conn)
// ...

I don't know anything about your use case but if your response data can be delivered piece wise then the streaming APIs might be useful.

like image 92
kingkupps Avatar answered Oct 21 '22 00:10

kingkupps