From f621e9ee0e8176b17bbfa1319b33d039bb08aff5 Mon Sep 17 00:00:00 2001 From: TonsnakeLin Date: Mon, 30 Jan 2023 14:25:17 +0800 Subject: [PATCH 1/3] enhance tidb_enable_gc_tuner Signed-off-by: TonsnakeLin --- domain/domain.go | 5 ++++- util/gctuner/tuner.go | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index 0d06fdc5a7a13..f309930f42b2a 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -69,6 +69,7 @@ import ( "github.com/pingcap/tidb/util/engine" "github.com/pingcap/tidb/util/etcd" "github.com/pingcap/tidb/util/expensivequery" + "github.com/pingcap/tidb/util/gctuner" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/memoryusagealarm" @@ -2110,7 +2111,9 @@ func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager) } case <-readMemTricker.C: - memory.ForceReadMemStats() + if gctuner.EnableGOGCTuner.Load() { + memory.ForceReadMemStats() + } } } } diff --git a/util/gctuner/tuner.go b/util/gctuner/tuner.go index ec74f48ec4be0..62b98590ec949 100644 --- a/util/gctuner/tuner.go +++ b/util/gctuner/tuner.go @@ -144,15 +144,18 @@ func (t *tuner) getGCPercent() uint32 { // tuning check the memory inuse and tune GC percent dynamically. // Go runtime ensure that it will be called serially. func (t *tuner) tuning() { + if EnableGOGCTuner.Load() { + return + } + inuse := readMemoryInuse() threshold := t.getThreshold() // stop gc tuning if threshold <= 0 { return } - if EnableGOGCTuner.Load() { - t.setGCPercent(calcGCPercent(inuse, threshold)) - } + + t.setGCPercent(calcGCPercent(inuse, threshold)) } // threshold = inuse + inuse * (gcPercent / 100) From 6d7a345432beddf73ff01044148e3e23bee87623 Mon Sep 17 00:00:00 2001 From: TonsnakeLin Date: Mon, 30 Jan 2023 16:02:45 +0800 Subject: [PATCH 2/3] fix by comments Signed-off-by: TonsnakeLin --- domain/domain.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index f309930f42b2a..0d06fdc5a7a13 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -69,7 +69,6 @@ import ( "github.com/pingcap/tidb/util/engine" "github.com/pingcap/tidb/util/etcd" "github.com/pingcap/tidb/util/expensivequery" - "github.com/pingcap/tidb/util/gctuner" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/memoryusagealarm" @@ -2111,9 +2110,7 @@ func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager) } case <-readMemTricker.C: - if gctuner.EnableGOGCTuner.Load() { - memory.ForceReadMemStats() - } + memory.ForceReadMemStats() } } } From f1d7ea6c8cbb5c750ae6fe973dd5fd4beef2a0ab Mon Sep 17 00:00:00 2001 From: TonsnakeLin Date: Mon, 30 Jan 2023 17:16:30 +0800 Subject: [PATCH 3/3] fix bug Signed-off-by: TonsnakeLin --- util/gctuner/tuner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/gctuner/tuner.go b/util/gctuner/tuner.go index 62b98590ec949..3332d77b93875 100644 --- a/util/gctuner/tuner.go +++ b/util/gctuner/tuner.go @@ -144,7 +144,7 @@ func (t *tuner) getGCPercent() uint32 { // tuning check the memory inuse and tune GC percent dynamically. // Go runtime ensure that it will be called serially. func (t *tuner) tuning() { - if EnableGOGCTuner.Load() { + if !EnableGOGCTuner.Load() { return }