diff --git a/config/config.go b/config/config.go index 7b7c47319be30..a7e2c4fb85c63 100644 --- a/config/config.go +++ b/config/config.go @@ -389,6 +389,7 @@ type Performance struct { DistinctAggPushDown bool `toml:"distinct-agg-push-down" json:"agg-push-down-join"` CommitterConcurrency int `toml:"committer-concurrency" json:"committer-concurrency"` MaxTxnTTL uint64 `toml:"max-txn-ttl" json:"max-txn-ttl"` + GOGC int `toml:"gogc" json:"gogc"` } // PlanCache is the PlanCache section of the config. @@ -627,6 +628,7 @@ var defaultConf = Config{ DistinctAggPushDown: false, CommitterConcurrency: 16, MaxTxnTTL: 10 * 60 * 1000, // 10min + GOGC: 100, }, ProxyProtocol: ProxyProtocol{ Networks: "", diff --git a/config/config.toml.example b/config/config.toml.example index 6556eee05ef1f..27de8e54831ca 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -269,6 +269,11 @@ committer-concurrency = 16 # max lifetime of transaction ttl manager. max-txn-ttl = 600000 +# The Go GC trigger factor, you can get more information about it at https://golang.org/pkg/runtime. +# If you encounter OOM when executing large query, you can decrease this value to trigger GC earlier. +# If you find the CPU used by GC is too high or GC is too frequent and impact your business you can increase this value. +gogc = 100 + [proxy-protocol] # PROXY protocol acceptable client networks. # Empty string means disable PROXY protocol, * means all networks. diff --git a/tidb-server/main.go b/tidb-server/main.go index f309173ff2c1d..2b5b5241ca495 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -512,6 +512,8 @@ func setGlobalVars() { runtime.GOMAXPROCS(int(cfg.Performance.MaxProcs)) metrics.MaxProcs.Set(float64(runtime.GOMAXPROCS(0))) + util.SetGOGC(cfg.Performance.GOGC) + ddlLeaseDuration := parseDuration(cfg.Lease) session.SetSchemaLease(ddlLeaseDuration) statsLeaseDuration := parseDuration(cfg.Performance.StatsLease) diff --git a/util/gogc.go b/util/gogc.go index 3d49112825901..67d69a476848b 100644 --- a/util/gogc.go +++ b/util/gogc.go @@ -34,6 +34,9 @@ func init() { // SetGOGC update GOGC and related metrics. func SetGOGC(val int) { + if val <= 0 { + val = 100 + } debug.SetGCPercent(val) metrics.GOGC.Set(float64(val)) atomic.StoreInt64(&gogcValue, int64(val))