From b390a2a0b9034f2ee71f786fbfc028fe14655254 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 16 Dec 2020 14:33:05 -0800 Subject: [PATCH] fix: reuser timers in erasure set hotpaths (#11106) reuser timers in - connectDisks() monitoring - healMRFRoutine() channel timeouts --- cmd/erasure-sets.go | 26 +++++++++++++++++++++++--- cmd/metacache-bucket.go | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cmd/erasure-sets.go b/cmd/erasure-sets.go index 3db81f756..c2d7808ee 100644 --- a/cmd/erasure-sets.go +++ b/cmd/erasure-sets.go @@ -245,10 +245,13 @@ func (s *erasureSets) connectDisks() { s.endpointStrings[setIndex*s.setDriveCount+diskIndex] = disk.String() s.erasureDisksMu.Unlock() go func(setIndex int) { + idler := time.NewTimer(100 * time.Millisecond) + defer idler.Stop() + // Send a new disk connect event with a timeout select { case s.disksConnectEvent <- diskConnectInfo{setIndex: setIndex}: - case <-time.After(100 * time.Millisecond): + case <-idler.C: } }(setIndex) }(endpoint) @@ -267,13 +270,22 @@ func (s *erasureSets) monitorAndConnectEndpoints(ctx context.Context, monitorInt // Pre-emptively connect the disks if possible. s.connectDisks() + monitor := time.NewTimer(monitorInterval) + defer monitor.Stop() + for { select { case <-ctx.Done(): return - case <-time.After(monitorInterval): + case <-monitor.C: s.connectDisks() } + + if !monitor.Stop() { + <-monitor.C + } + + monitor.Reset(monitorInterval) } } @@ -1363,6 +1375,9 @@ func (s *erasureSets) healMRFRoutine() { // Wait until background heal state is initialized bgSeq := mustGetHealSequence(GlobalContext) + idler := time.NewTimer(100 * time.Millisecond) + defer idler.Stop() + for e := range s.disksConnectEvent { // Get the list of objects related the er.set // to which the connected disk belongs. @@ -1380,9 +1395,14 @@ func (s *erasureSets) healMRFRoutine() { // Send an object to be healed with a timeout select { case bgSeq.sourceCh <- u: - case <-time.After(100 * time.Millisecond): + case <-idler.C: } + if !idler.Stop() { + <-idler.C + } + idler.Reset(100 * time.Millisecond) + s.mrfMU.Lock() delete(s.mrfOperations, u) s.mrfMU.Unlock() diff --git a/cmd/metacache-bucket.go b/cmd/metacache-bucket.go index e151de6ab..a68b3a244 100644 --- a/cmd/metacache-bucket.go +++ b/cmd/metacache-bucket.go @@ -87,7 +87,8 @@ func loadBucketMetaCache(ctx context.Context, bucket string) (*bucketMetacache, select { case <-ctx.Done(): return nil, ctx.Err() - case <-time.After(250 * time.Millisecond): + default: + time.Sleep(250 * time.Millisecond) } objAPI = newObjectLayerFn() if objAPI == nil {