Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting grpc send and recv message sizes independently #481

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added go/cmd/vtgateproxy/vtgateproxy
Binary file not shown.
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtbackup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Usage of vtbackup:
--grpc_initial_window_size int gRPC initial window size
--grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s)
--grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_prometheus Enable gRPC monitoring with Prometheus.
-h, --help display usage and exit
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtctlclient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Usage of vtctlclient:
--grpc_initial_window_size int gRPC initial window size
--grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s)
--grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_prometheus Enable gRPC monitoring with Prometheus.
-h, --help display usage and exit
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtctld.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Usage of vtctld:
--grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS
--grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s)
--grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_port int Port to listen on for gRPC calls. If zero, do not listen.
--grpc_prometheus Enable gRPC monitoring with Prometheus.
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtctldclient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Flags:
--grpc_initial_window_size int gRPC initial window size
--grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s)
--grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_prometheus Enable gRPC monitoring with Prometheus.
-h, --help help for vtctldclient
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtgate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Usage of vtgate:
--grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS
--grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s)
--grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_port int Port to listen on for gRPC calls. If zero, do not listen.
--grpc_prometheus Enable gRPC monitoring with Prometheus.
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtgr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Usage of vtgr:
--grpc_initial_window_size int gRPC initial window size
--grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s)
--grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_prometheus Enable gRPC monitoring with Prometheus.
-h, --help display usage and exit
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vtorc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Usage of vtorc:
--grpc_initial_window_size int gRPC initial window size
--grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s)
--grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_prometheus Enable gRPC monitoring with Prometheus.
-h, --help display usage and exit
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vttablet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Usage of vttablet:
--grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS
--grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s)
--grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_port int Port to listen on for gRPC calls. If zero, do not listen.
--grpc_prometheus Enable gRPC monitoring with Prometheus.
Expand Down
2 changes: 2 additions & 0 deletions go/flags/endtoend/vttestserver.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Usage of vttestserver:
--grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS
--grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s)
--grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s)
--grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.
--grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.
--grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216)
--grpc_port int Port to listen on for gRPC calls. If zero, do not listen.
--grpc_prometheus Enable gRPC monitoring with Prometheus.
Expand Down
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
20 changes: 20 additions & 0 deletions go/vt/grpccommon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ 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
// These options override maxMessageSize if > 0, allowing us to control the max
// size sending independently from receiving.
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 +47,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, "Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.")
fs.IntVar(&maxMsgRecvSize, "grpc_max_message_recv_size", maxMsgRecvSize, "Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.")
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 +76,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
Loading