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

server: add grpc server config for a suitable behavior #30774

Merged
merged 4 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 21 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,17 @@ func (s *Security) ClusterSecurity() tikvcfg.Security {

// Status is the status section of the config.
type Status struct {
StatusHost string `toml:"status-host" json:"status-host"`
MetricsAddr string `toml:"metrics-addr" json:"metrics-addr"`
StatusPort uint `toml:"status-port" json:"status-port"`
MetricsInterval uint `toml:"metrics-interval" json:"metrics-interval"`
ReportStatus bool `toml:"report-status" json:"report-status"`
RecordQPSbyDB bool `toml:"record-db-qps" json:"record-db-qps"`
StatusHost string `toml:"status-host" json:"status-host"`
MetricsAddr string `toml:"metrics-addr" json:"metrics-addr"`
StatusPort uint `toml:"status-port" json:"status-port"`
MetricsInterval uint `toml:"metrics-interval" json:"metrics-interval"`
ReportStatus bool `toml:"report-status" json:"report-status"`
RecordQPSbyDB bool `toml:"record-db-qps" json:"record-db-qps"`
GRPCKeepAliveTime uint `toml:"grpc-keepalive-time" json:"grpc-keepalive-time"`
GRPCKeepAliveTimeout uint `toml:"grpc-keepalive-timeout" json:"grpc-keepalive-timeout"`
GRPCConcurrentStreams uint `toml:"grpc-concurrent-streams" json:"grpc-concurrent-streams"`
GRPCInitialWindowSize int `toml:"grpc-initial-window-size" json:"grpc-initial-window-size"`
GRPCMaxSendMsgSize int `toml:"grpc-max-send-msg-size" json:"grpc-max-send-msg-size"`
}

// Performance is the performance section of the config.
Expand Down Expand Up @@ -658,11 +663,16 @@ var defaultConf = Config{
EnableSlowLog: *NewAtomicBool(logutil.DefaultTiDBEnableSlowLog),
},
Status: Status{
ReportStatus: true,
StatusHost: DefStatusHost,
StatusPort: DefStatusPort,
MetricsInterval: 15,
RecordQPSbyDB: false,
ReportStatus: true,
StatusHost: DefStatusHost,
StatusPort: DefStatusPort,
MetricsInterval: 15,
RecordQPSbyDB: false,
GRPCKeepAliveTime: 10,
GRPCKeepAliveTimeout: 3,
GRPCConcurrentStreams: 1024,
GRPCInitialWindowSize: 2 * 1024 * 1024,
GRPCMaxSendMsgSize: 10 * 1024 * 1024,
},
Performance: Performance{
MaxMemory: 0,
Expand Down
17 changes: 17 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ metrics-interval = 15
# Record statements qps by database name if it is enabled.
record-db-qps = false

# After a duration of this time in seconds if the server doesn't see any activity it pings
# the client to see if the transport is still alive.
grpc-keepalive-time = 10

# After having pinged for keepalive check, the server waits for a duration of timeout in seconds
# and if no activity is seen even after that the connection is closed.
grpc-keepalive-timeout = 3

# The number of max concurrent streams/requests on a client connection.
grpc-concurrent-streams = 1024

# Sets window size for stream. The default value is 2MB.
grpc-initial-window-size = 2097152

# Set maximum message length in bytes that gRPC can send. `-1` means unlimited. The default value is 10MB.
grpc-max-send-msg-size = 10485760

[performance]
# Max CPUs to use, 0 use number of CPUs in the machine.
max-procs = 0
Expand Down
12 changes: 11 additions & 1 deletion server/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"net"
"time"

"github.com/pingcap/kvproto/pkg/coprocessor"
"github.com/pingcap/kvproto/pkg/diagnosticspb"
Expand All @@ -34,6 +35,7 @@ import (
"github.com/pingcap/tidb/util/memory"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/peer"
)

Expand All @@ -46,7 +48,15 @@ func NewRPCServer(config *config.Config, dom *domain.Domain, sm util.SessionMana
}
}()

s := grpc.NewServer()
s := grpc.NewServer(
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: time.Duration(config.Status.GRPCKeepAliveTime) * time.Second,
Timeout: time.Duration(config.Status.GRPCKeepAliveTimeout) * time.Second,
}),
grpc.MaxConcurrentStreams(uint32(config.Status.GRPCConcurrentStreams)),
grpc.InitialWindowSize(int32(config.Status.GRPCInitialWindowSize)),
grpc.MaxSendMsgSize(config.Status.GRPCMaxSendMsgSize),
)
rpcSrv := &rpcServer{
DiagnosticsServer: sysutil.NewDiagnosticsServer(config.Log.File.Filename),
dom: dom,
Expand Down