Skip to content

Commit

Permalink
config: add GOGC under performance section (pingcap#20872)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zejun Li committed Nov 9, 2020
1 parent 45571c5 commit 91cb13b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,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.
Expand Down Expand Up @@ -623,6 +624,7 @@ var defaultConf = Config{
DistinctAggPushDown: false,
CommitterConcurrency: 16,
MaxTxnTTL: 10 * 60 * 1000, // 10min
GOGC: 100,
},
ProxyProtocol: ProxyProtocol{
Networks: "",
Expand Down
5 changes: 5 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,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.
Expand Down
2 changes: 2 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions util/gogc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 91cb13b

Please sign in to comment.