Skip to content

Commit 5c15bf4

Browse files
committed
Prevent GC from schedule itself with 0 period.
On startup `gcTimeSum` might work fast and return `0`, so on this case the algorithm turns in infinity loop which simple consume CPU on timer which fires without any interval. Use `5ms` as fallback to have interval `245ms` for that case. Closes: #5089 Signed-off-by: Kirill A. Korinsky <[email protected]>
1 parent c37fe74 commit 5c15bf4

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

gc/scheduler/scheduler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func schedule(d time.Duration) (<-chan time.Time, *time.Time) {
246246
}
247247

248248
func (s *gcScheduler) run(ctx context.Context) {
249+
const minimumGCTime = float64(5 * time.Millisecond)
249250
var (
250251
schedC <-chan time.Time
251252

@@ -343,6 +344,11 @@ func (s *gcScheduler) run(ctx context.Context) {
343344
// runtime in between gc to reach the pause threshold.
344345
// Pause threshold is always 0.0 < threshold <= 0.5
345346
avg := float64(gcTimeSum) / float64(collections)
347+
// Enforce that avg is no less than minimumGCTime
348+
// to prevent immediate rescheduling
349+
if avg < minimumGCTime {
350+
avg = minimumGCTime
351+
}
346352
interval = time.Duration(avg/s.pauseThreshold - avg)
347353
}
348354

0 commit comments

Comments
 (0)