From 44e23b7f4f3b8fe7e92f9d10d1cea864ecd50d84 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 2 Dec 2020 21:03:45 -0800 Subject: [PATCH] fix: startup being slow - wait only if IOCount > 0 --- cmd/admin-heal-ops.go | 4 +++- cmd/background-heal-ops.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/admin-heal-ops.go b/cmd/admin-heal-ops.go index 583eccd45..3450f45f4 100644 --- a/cmd/admin-heal-ops.go +++ b/cmd/admin-heal-ops.go @@ -676,7 +676,9 @@ func (h *healSequence) queueHealTask(source healSource, healType madmin.HealItem } // Wait and proceed if there are active requests - waitForLowHTTPReq(opts.IOCount, opts.Sleep) + if opts.IOCount > 0 { + waitForLowHTTPReq(opts.IOCount, opts.Sleep) + } h.mutex.Lock() h.scannedItemsMap[healType]++ diff --git a/cmd/background-heal-ops.go b/cmd/background-heal-ops.go index a4886d64f..d41b7ea81 100644 --- a/cmd/background-heal-ops.go +++ b/cmd/background-heal-ops.go @@ -54,20 +54,25 @@ func (h *healRoutine) queueHealTask(task healTask) { h.tasks <- task } -func waitForLowHTTPReq(tolerance int, maxWait time.Duration) { +func waitForLowHTTPReq(maxIO int, maxWait time.Duration) { + // No need to wait run at full speed. + if maxIO <= 0 { + return + } + // At max 10 attempts to wait with 100 millisecond interval before proceeding waitCount := 10 waitTick := 100 * time.Millisecond // Bucket notification and http trace are not costly, it is okay to ignore them // while counting the number of concurrent connections - toleranceFn := func() int { - return tolerance + globalHTTPListen.NumSubscribers() + globalHTTPTrace.NumSubscribers() + maxIOFn := func() int { + return maxIO + globalHTTPListen.NumSubscribers() + globalHTTPTrace.NumSubscribers() } if httpServer := newHTTPServerFn(); httpServer != nil { // Any requests in progress, delay the heal. - for httpServer.GetRequestCount() >= toleranceFn() { + for httpServer.GetRequestCount() >= maxIOFn() { time.Sleep(waitTick) waitCount-- if waitCount == 0 {