From 60e950015c347d4d86e6db1d76547a706706960c Mon Sep 17 00:00:00 2001 From: zgfzgf <1901989065@qq.com> Date: Fri, 25 Sep 2020 22:13:27 +0800 Subject: [PATCH 1/3] modify for unsafe --- extern/sector-storage/sched.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extern/sector-storage/sched.go b/extern/sector-storage/sched.go index 8b8ef6d46..89a4d6f3f 100644 --- a/extern/sector-storage/sched.go +++ b/extern/sector-storage/sched.go @@ -417,6 +417,7 @@ func (sh *scheduler) trySched() { // Step 2 scheduled := 0 + rmQueue := make([]int, 0, sh.schedQueue.Len()) for sqi := 0; sqi < sh.schedQueue.Len(); sqi++ { task := (*sh.schedQueue)[sqi] @@ -453,11 +454,16 @@ func (sh *scheduler) trySched() { windows[selectedWindow].todo = append(windows[selectedWindow].todo, task) - sh.schedQueue.Remove(sqi) - sqi-- + rmQueue = append(rmQueue, sqi) scheduled++ } + if len(rmQueue) > 0 { + for i := len(rmQueue) - 1; i >= 0; i++ { + sh.schedQueue.Remove(rmQueue[i]) + } + } + // Step 3 if scheduled == 0 { From 3207bc4704b5a6b4241bcc4289bf82ace9d070f9 Mon Sep 17 00:00:00 2001 From: zgfzgf <1901989065@qq.com> Date: Fri, 25 Sep 2020 22:41:29 +0800 Subject: [PATCH 2/3] optimize trySched --- extern/sector-storage/sched.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/extern/sector-storage/sched.go b/extern/sector-storage/sched.go index 89a4d6f3f..e12471c20 100644 --- a/extern/sector-storage/sched.go +++ b/extern/sector-storage/sched.go @@ -318,26 +318,28 @@ func (sh *scheduler) trySched() { */ - windows := make([]schedWindow, len(sh.openWindows)) - acceptableWindows := make([][]int, sh.schedQueue.Len()) - - log.Debugf("SCHED %d queued; %d open windows", sh.schedQueue.Len(), len(windows)) - sh.workersLk.RLock() defer sh.workersLk.RUnlock() - if len(sh.openWindows) == 0 { + + windowsLen := len(sh.openWindows) + queuneLen := sh.schedQueue.Len() + + log.Debugf("SCHED %d queued; %d open windows", queuneLen, windowsLen) + + if windowsLen == 0 || queuneLen == 0 { // nothing to schedule on return } + windows := make([]schedWindow, windowsLen) + acceptableWindows := make([][]int, queuneLen) + // Step 1 - concurrency := len(sh.openWindows) - throttle := make(chan struct{}, concurrency) + throttle := make(chan struct{}, windowsLen) var wg sync.WaitGroup - wg.Add(sh.schedQueue.Len()) - - for i := 0; i < sh.schedQueue.Len(); i++ { + wg.Add(queuneLen) + for i := 0; i < queuneLen; i++ { throttle <- struct{}{} go func(sqi int) { @@ -417,9 +419,9 @@ func (sh *scheduler) trySched() { // Step 2 scheduled := 0 - rmQueue := make([]int, 0, sh.schedQueue.Len()) + rmQueue := make([]int, 0, queuneLen) - for sqi := 0; sqi < sh.schedQueue.Len(); sqi++ { + for sqi := 0; sqi < queuneLen; sqi++ { task := (*sh.schedQueue)[sqi] needRes := ResourceTable[task.taskType][sh.spt] @@ -488,7 +490,7 @@ func (sh *scheduler) trySched() { } // Rewrite sh.openWindows array, removing scheduled windows - newOpenWindows := make([]*schedWindowRequest, 0, len(sh.openWindows)-len(scheduledWindows)) + newOpenWindows := make([]*schedWindowRequest, 0, windowsLen-len(scheduledWindows)) for wnd, window := range sh.openWindows { if _, scheduled := scheduledWindows[wnd]; scheduled { // keep unscheduled windows open From 1a7aea1906c4e484b6c6771492ee8a10626c45cf Mon Sep 17 00:00:00 2001 From: zgfzgf <1901989065@qq.com> Date: Fri, 25 Sep 2020 22:59:21 +0800 Subject: [PATCH 3/3] modify error --- extern/sector-storage/sched.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/sector-storage/sched.go b/extern/sector-storage/sched.go index e12471c20..a2c1ca565 100644 --- a/extern/sector-storage/sched.go +++ b/extern/sector-storage/sched.go @@ -461,7 +461,7 @@ func (sh *scheduler) trySched() { } if len(rmQueue) > 0 { - for i := len(rmQueue) - 1; i >= 0; i++ { + for i := len(rmQueue) - 1; i >= 0; i-- { sh.schedQueue.Remove(rmQueue[i]) } }