Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 committed Sep 28, 2022
1 parent 65fa37c commit 77870f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions util/gctuner/memory_limit_tuner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ var GlobalMemoryLimitTuner = &memoryLimitTuner{}
// Go runtime trigger GC when hit memory limit which managed via runtime/debug.SetMemoryLimit.
// So we can change memory limit dynamically to avoid frequent GC when memory usage is greater than the soft limit.
type memoryLimitTuner struct {
finalizer *finalizer
isTuning atomic.Bool
percentage atomicutil.Float64
coolDown atomic.Bool
times int
finalizer *finalizer
isTuning atomic.Bool
percentage atomicutil.Float64
waitingReset atomic.Bool
times int // The times that nextGC bigger than MemoryLimit
}

// tuning check the memory nextGC and judge whether this GC is trigger by memory limit.
Expand All @@ -54,19 +54,19 @@ func (t *memoryLimitTuner) tuning() {
// the second GC is caused by MemoryLimit.
if r.HeapInuse > uint64(float64(debug.SetMemoryLimit(-1))/ratio) {
t.times++
if t.times >= 2 && t.coolDown.CompareAndSwap(false, true) {
if t.times >= 2 && t.waitingReset.CompareAndSwap(false, true) {
t.times = 0
go func() {
debug.SetMemoryLimit(math.MaxInt)
coolDownTime := 1 * time.Minute // 1 minute to cool down, to avoid frequent GC
resetInterval := 1 * time.Minute // Wait 1 minute and set back, to avoid frequent GC
failpoint.Inject("testMemoryLimitTuner", func(val failpoint.Value) {
if val.(bool) {
coolDownTime = 1 * time.Second
resetInterval = 1 * time.Second
}
})
time.Sleep(coolDownTime)
time.Sleep(resetInterval)
debug.SetMemoryLimit(t.calcSoftMemoryLimit())
for !t.coolDown.CompareAndSwap(true, false) {
for !t.waitingReset.CompareAndSwap(true, false) {
continue
}
}()
Expand Down
2 changes: 1 addition & 1 deletion util/gctuner/memory_limit_tuner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestGlobalMemoryTuner(t *testing.T) {

memory210mb := allocator.alloc(210 << 20)
require.True(t, gcNum < getNowGCNum())
// Test Cool Down
// Test waiting for reset
time.Sleep(500 * time.Millisecond)
require.Equal(t, int64(math.MaxInt64), debug.SetMemoryLimit(-1))
gcNum = getNowGCNum()
Expand Down

0 comments on commit 77870f3

Please sign in to comment.