Skip to content
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
5 changes: 4 additions & 1 deletion pkg/balance/factor/factor_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ func calcMemUsage(usageHistory []model.SamplePair) (latestUsage float64, timeToO
continue
}
usageDiff := latestUsage - value
if usageDiff > 1e-4 {
if usageDiff > 1e-4 && latestUsage > 1e-4 {
timeToOOM = time.Duration(float64(timeDiff) * (oomMemoryUsage - latestUsage) / usageDiff)
// When the backend just starts, the memory usage usually bursts but is actually safe.
// Adjust timeToOOM so that the same growth rate is less urgent at lower memory usage.
timeToOOM = time.Duration(float64(timeToOOM) / latestUsage * 0.6)
}
break
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/balance/factor/factor_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestMemoryScore(t *testing.T) {
},
{
memory: []float64{0, 0.1},
score: 1,
score: 0,
},
{
memory: []float64{1.0, 0.95},
Expand Down Expand Up @@ -121,13 +121,13 @@ func TestMemoryUsage(t *testing.T) {
memory: []float64{0.2, 0.3},
ts: []model.Time{model.Time(15000), model.Time(30000)},
lastUsage: 0.3,
timeToOOM: 90 * time.Second,
timeToOOM: 3 * time.Minute,
},
{
memory: []float64{0.2, 0.3, 0.3},
ts: []model.Time{model.Time(15000), model.Time(30000), model.Time(31000)},
lastUsage: 0.3,
timeToOOM: 96 * time.Second,
timeToOOM: 192 * time.Second,
},
{
memory: []float64{0.3, 0.3},
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestMemoryBalance(t *testing.T) {
}{
{
memory: [][]float64{{0.2, 0.3}, {0.3, 0.4}},
scores: []uint64{1, 1},
scores: []uint64{0, 1},
balanced: true,
},
{
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestMemoryBalanceCount(t *testing.T) {
case 1:
usage = []float64{0.8, 0.8}
case 2:
usage = []float64{0.1, 0.4}
usage = []float64{0.75, 0.88}
}
ts = ts.Add(time.Millisecond)
values := []*model.SampleStream{
Expand Down