Skip to content

Commit

Permalink
Allow setting grpc send and recv message sizes independently
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Robinson <hrobinson@slack-corp.com>
  • Loading branch information
henryr committed Aug 9, 2024
1 parent 1b333db commit f29b478
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 4 additions & 3 deletions go/vt/grpcclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ func Dial(target string, failFast FailFast, opts ...grpc.DialOption) (*grpc.Clie
// what that should be.
func DialContext(ctx context.Context, target string, failFast FailFast, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
grpccommon.EnableTracingOpt()
msgSize := grpccommon.MaxMessageSize()
maxSendSize := grpccommon.MaxMessageSendSize()
maxRecvSize := grpccommon.MaxMessageRecvSize()
newopts := []grpc.DialOption{
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(msgSize),
grpc.MaxCallSendMsgSize(msgSize),
grpc.MaxCallRecvMsgSize(maxRecvSize),
grpc.MaxCallSendMsgSize(maxSendSize),
grpc.WaitForReady(bool(!failFast)),
),
}
Expand Down
18 changes: 18 additions & 0 deletions go/vt/grpccommon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var (
// accept. Larger messages will be rejected.
// Note: We're using 16 MiB as default value because that's the default in MySQL
maxMessageSize = 16 * 1024 * 1024
maxMsgRecvSize = 0
maxMsgSendSize = 0
// enableTracing sets a flag to enable grpc client/server tracing.
enableTracing bool
// enablePrometheus sets a flag to enable grpc client/server grpc monitoring.
Expand All @@ -43,6 +45,8 @@ var (
// command-line arguments.
func RegisterFlags(fs *pflag.FlagSet) {
fs.IntVar(&maxMessageSize, "grpc_max_message_size", maxMessageSize, "Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'.")
fs.IntVar(&maxMsgSendSize, "grpc_max_message_send_size", maxMsgSendSize, "")
fs.IntVar(&maxMsgRecvSize, "grpc_max_message_recv_size", maxMsgRecvSize, "")
fs.BoolVar(&enableTracing, "grpc_enable_tracing", enableTracing, "Enable gRPC tracing.")
fs.BoolVar(&enablePrometheus, "grpc_prometheus", enablePrometheus, "Enable gRPC monitoring with Prometheus.")
}
Expand Down Expand Up @@ -70,6 +74,20 @@ func MaxMessageSize() int {
return maxMessageSize
}

func MaxMessageRecvSize() int {
if maxMsgRecvSize > 0 {
return maxMsgRecvSize
}
return MaxMessageSize()
}

func MaxMessageSendSize() int {
if maxMsgSendSize > 0 {
return maxMsgSendSize
}
return MaxMessageSize()
}

func init() {
stats.NewString("GrpcVersion").Set(grpc.Version)
}
10 changes: 6 additions & 4 deletions go/vt/servenv/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ func createGRPCServer() {
// grpc: received message length XXXXXXX exceeding the max size 4194304
// Note: For gRPC 1.0.0 it's sufficient to set the limit on the server only
// because it's not enforced on the client side.
msgSize := grpccommon.MaxMessageSize()
log.Infof("Setting grpc max message size to %d", msgSize)
opts = append(opts, grpc.MaxRecvMsgSize(msgSize))
opts = append(opts, grpc.MaxSendMsgSize(msgSize))

maxSendSize := grpccommon.MaxMessageSendSize()
maxRecvSize := grpccommon.MaxMessageRecvSize()
log.Infof("Setting grpc server max message sizes to %d (sending), %d (receiving)", maxSendSize, maxRecvSize)
opts = append(opts, grpc.MaxRecvMsgSize(maxRecvSize))
opts = append(opts, grpc.MaxSendMsgSize(maxSendSize))

if gRPCInitialConnWindowSize != 0 {
log.Infof("Setting grpc server initial conn window size to %d", int32(gRPCInitialConnWindowSize))
Expand Down

0 comments on commit f29b478

Please sign in to comment.