Skip to content

Commit

Permalink
support setting keepalive for server
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Jan 21, 2025
1 parent a69ee01 commit a00ff2e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ type Config struct {

MaxRequestBytes uint `toml:"max-request-bytes" json:"max-request-bytes"`

// GRPCKeepAliveInterval is the frequency of server-to-client ping
// to check if a connection is alive. Close a non-responsive connection
// after an additional duration of Timeout. 0 to disable.
GRPCKeepAliveInterval time.Duration `json:"grpc-keepalive-interval"`
// GRPCKeepAliveTimeout is the additional duration of wait
// before closing a non-responsive connection. 0 to disable.
GRPCKeepAliveTimeout time.Duration `json:"grpc-keepalive-timeout"`

Security configutil.SecurityConfig `toml:"security" json:"security"`

LabelProperty LabelPropertyConfig `toml:"label-property" json:"label-property"`
Expand Down Expand Up @@ -182,6 +190,9 @@ const (
// then 150MB can fit for store reports that have about 300k regions which is something of a huge amount of region on one TiKV.
defaultMaxRequestBytes = uint(150 * units.MiB) // 150MB

defaultGRPCKeepAliveInterval = 10 * time.Second
defaultGRPCKeepAliveTimeout = 3 * time.Second

defaultName = "pd"
defaultClientUrls = "http://127.0.0.1:2379"
defaultPeerUrls = "http://127.0.0.1:2380"
Expand Down Expand Up @@ -422,6 +433,12 @@ func (c *Config) Adjust(meta *toml.MetaData, reloading bool) error {
if !configMetaData.IsDefined("max-request-bytes") {
c.MaxRequestBytes = defaultMaxRequestBytes
}
if !configMetaData.IsDefined("grpc-keepalive-interval") {
c.GRPCKeepAliveInterval = defaultGRPCKeepAliveInterval
}
if !configMetaData.IsDefined("grpc-keepalive-timeout") {
c.GRPCKeepAliveTimeout = defaultGRPCKeepAliveTimeout
}
configutil.AdjustDuration(&c.TickInterval, defaultTickInterval)
configutil.AdjustDuration(&c.ElectionInterval, defaultElectionInterval)

Expand Down Expand Up @@ -694,6 +711,8 @@ func (c *Config) GenEmbedEtcdConfig() (*embed.Config, error) {
cfg.AutoCompactionRetention = c.AutoCompactionRetention
cfg.QuotaBackendBytes = int64(c.QuotaBackendBytes)
cfg.MaxRequestBytes = c.MaxRequestBytes
cfg.GRPCKeepAliveInterval = c.GRPCKeepAliveInterval
cfg.GRPCKeepAliveTimeout = c.GRPCKeepAliveTimeout

cfg.ClientTLSInfo.ClientCertAuth = len(c.Security.CAPath) != 0
cfg.ClientTLSInfo.TrustedCAFile = c.Security.CAPath
Expand Down

0 comments on commit a00ff2e

Please sign in to comment.