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(ticdc): use TiDB gcTuner in a more reasonable way #9786

Merged
merged 6 commits into from
Sep 22, 2023
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
31 changes: 16 additions & 15 deletions cdc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/pingcap/tiflow/pkg/p2p"
"github.com/pingcap/tiflow/pkg/pdutil"
"github.com/pingcap/tiflow/pkg/tcpserver"
"github.com/pingcap/tiflow/pkg/util"
p2pProto "github.com/pingcap/tiflow/proto/p2p"
pd "github.com/tikv/pd/client"
"go.uber.org/zap"
Expand All @@ -57,6 +56,8 @@ const (
maxHTTPConnection = 1000
// httpConnectionTimeout is used to limit a connection max alive time of http server.
httpConnectionTimeout = 10 * time.Minute
// maxGcTunerMemory is used to limit the max memory usage of cdc server. if the memory is larger than it, gc tuner will be disabled
maxGcTunerMemory = 512 * 1024 * 1024 * 1024
)

// Server is the interface for the TiCDC server
Expand Down Expand Up @@ -194,32 +195,32 @@ func (s *server) prepare(ctx context.Context) error {
}

s.createSortEngineFactory()

if err := s.setMemoryLimit(); err != nil {
return errors.Trace(err)
}
s.setMemoryLimit()

s.capture = capture.NewCapture(s.pdEndpoints, cdcEtcdClient,
s.grpcService, s.sortEngineFactory, s.pdClient)
return nil
}

func (s *server) setMemoryLimit() error {
func (s *server) setMemoryLimit() {
conf := config.GetGlobalServerConfig()
totalMemory, err := util.GetMemoryLimit()
if err != nil {
return errors.Trace(err)
if conf.GcTunerMemoryThreshold > maxGcTunerMemory {
// If total memory is larger than 512GB, we will not set memory limit.
// Because the memory limit is not accurate, and it is not necessary to set memory limit.
log.Info("total memory is larger than 512GB, skip setting memory limit",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.warn

zap.Uint64("bytes", conf.GcTunerMemoryThreshold),
zap.String("memory", humanize.IBytes(conf.GcTunerMemoryThreshold)),
)
return
}
if conf.MaxMemoryPercentage > 0 {
goMemLimit := totalMemory * uint64(conf.MaxMemoryPercentage) / 100
if conf.GcTunerMemoryThreshold > 0 {
gctuner.EnableGOGCTuner.Store(true)
gctuner.Tuning(goMemLimit)
gctuner.Tuning(conf.GcTunerMemoryThreshold)
log.Info("enable gctuner, set memory limit",
zap.Uint64("bytes", goMemLimit),
zap.String("memory", humanize.IBytes(goMemLimit)),
zap.Uint64("bytes", conf.GcTunerMemoryThreshold),
zap.String("memory", humanize.IBytes(conf.GcTunerMemoryThreshold)),
)
}
return nil
}

func (s *server) createSortEngineFactory() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestParseCfg(t *testing.T) {
},
},
ClusterID: "default",
MaxMemoryPercentage: config.DefaultMaxMemoryPercentage,
MaxMemoryPercentage: config.DisableMemoryLimit,
}, o.serverConfig)
}

Expand Down Expand Up @@ -339,7 +339,7 @@ check-balance-interval = "10s"
},
},
ClusterID: "default",
MaxMemoryPercentage: config.DefaultMaxMemoryPercentage,
MaxMemoryPercentage: config.DisableMemoryLimit,
}, o.serverConfig)
}

Expand Down Expand Up @@ -470,7 +470,7 @@ cert-allowed-cn = ["dd","ee"]
},
},
ClusterID: "default",
MaxMemoryPercentage: config.DefaultMaxMemoryPercentage,
MaxMemoryPercentage: config.DisableMemoryLimit,
}, o.serverConfig)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/config/config_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ const (
}
},
"cluster-id": "default",
"max-memory-percentage": 70
"max-memory-percentage": 0,
"gc-tuner-memory-threshold": 0
}`

testCfgTestReplicaConfigMarshal1 = `{
Expand Down
19 changes: 8 additions & 11 deletions pkg/config/server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ const (
// DefaultChangefeedMemoryQuota is the default memory quota for each changefeed.
DefaultChangefeedMemoryQuota = 1024 * 1024 * 1024 // 1GB.

// DefaultMaxMemoryPercentage is the default max memory percentage
// cdc server use 70% of total memory limit as soft limit by default.
DefaultMaxMemoryPercentage = 70
// DisableMemoryLimit is the default max memory percentage for TiCDC server.
// 0 means no memory limit.
DisableMemoryLimit = 0
)

var (
Expand Down Expand Up @@ -137,8 +137,8 @@ var defaultServerConfig = &ServerConfig{

Scheduler: NewDefaultSchedulerConfig(),
},
ClusterID: "default",
MaxMemoryPercentage: DefaultMaxMemoryPercentage,
ClusterID: "default",
GcTunerMemoryThreshold: DisableMemoryLimit,
}

// ServerConfig represents a config for server
Expand Down Expand Up @@ -167,7 +167,9 @@ type ServerConfig struct {
KVClient *KVClientConfig `toml:"kv-client" json:"kv-client"`
Debug *DebugConfig `toml:"debug" json:"debug"`
ClusterID string `toml:"cluster-id" json:"cluster-id"`
MaxMemoryPercentage int `toml:"max-memory-percentage" json:"max-memory-percentage"`
// Deprecated: we don't use this field anymore.
MaxMemoryPercentage int `toml:"max-memory-percentage" json:"max-memory-percentage"`
GcTunerMemoryThreshold uint64 `toml:"gc-tuner-memory-threshold" json:"gc-tuner-memory-threshold"`
}

// Marshal returns the json marshal format of a ServerConfig
Expand Down Expand Up @@ -278,11 +280,6 @@ func (c *ServerConfig) ValidateAndAdjust() error {
if err = c.Debug.ValidateAndAdjust(); err != nil {
return errors.Trace(err)
}
if c.MaxMemoryPercentage >= 100 {
log.Warn("server max-memory-percentage must be less than 100, set to default value")
c.MaxMemoryPercentage = DefaultMaxMemoryPercentage
}

return nil
}

Expand Down
Loading