From e14c80360dd80661f020ce5759035c22a66198ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 31 Aug 2020 13:31:11 +0200 Subject: [PATCH] sealing sched: Factor worker queues into utilization calc --- extern/sector-storage/sched.go | 4 ++++ extern/sector-storage/sched_resources.go | 14 ++++++++++++++ extern/sector-storage/selector_alloc.go | 2 +- extern/sector-storage/selector_existing.go | 2 +- extern/sector-storage/selector_task.go | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/extern/sector-storage/sched.go b/extern/sector-storage/sched.go index 56d78bfae..93ba89ace 100644 --- a/extern/sector-storage/sched.go +++ b/extern/sector-storage/sched.go @@ -437,6 +437,10 @@ func (sh *scheduler) trySched() { log.Debugf("SCHED ASSIGNED sqi:%d sector %d task %s to window %d", sqi, task.sector.Number, task.taskType, wnd) windows[wnd].allocated.add(wr, needRes) + // TODO: We probably want to re-sort acceptableWindows here based on new + // workerHandle.utilization + windows[wnd].allocated.utilization (workerHandle.utilization is used in all + // task selectors, but not in the same way, so need to figure out how to do that in a non-O(n^2 way), and + // without additional network roundtrips (O(n^2) could be avoided by turning acceptableWindows.[] into heaps)) selectedWindow = wnd break diff --git a/extern/sector-storage/sched_resources.go b/extern/sector-storage/sched_resources.go index 92a3b32ad..623472a20 100644 --- a/extern/sector-storage/sched_resources.go +++ b/extern/sector-storage/sched_resources.go @@ -108,3 +108,17 @@ func (a *activeResources) utilization(wr storiface.WorkerResources) float64 { return max } + +func (wh *workerHandle) utilization() float64 { + wh.lk.Lock() + u := wh.active.utilization(wh.info.Resources) + u += wh.preparing.utilization(wh.info.Resources) + wh.lk.Unlock() + wh.wndLk.Lock() + for _, window := range wh.activeWindows { + u += window.allocated.utilization(wh.info.Resources) + } + wh.wndLk.Unlock() + + return u +} diff --git a/extern/sector-storage/selector_alloc.go b/extern/sector-storage/selector_alloc.go index 57ac6c124..ca4b99bfc 100644 --- a/extern/sector-storage/selector_alloc.go +++ b/extern/sector-storage/selector_alloc.go @@ -59,7 +59,7 @@ func (s *allocSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi } func (s *allocSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *workerHandle) (bool, error) { - return a.active.utilization(a.info.Resources) < b.active.utilization(b.info.Resources), nil + return a.utilization() < b.utilization(), nil } var _ WorkerSelector = &allocSelector{} diff --git a/extern/sector-storage/selector_existing.go b/extern/sector-storage/selector_existing.go index fda084672..1e97db539 100644 --- a/extern/sector-storage/selector_existing.go +++ b/extern/sector-storage/selector_existing.go @@ -61,7 +61,7 @@ func (s *existingSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt } func (s *existingSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *workerHandle) (bool, error) { - return a.active.utilization(a.info.Resources) < b.active.utilization(b.info.Resources), nil + return a.utilization() < b.utilization(), nil } var _ WorkerSelector = &existingSelector{} diff --git a/extern/sector-storage/selector_task.go b/extern/sector-storage/selector_task.go index 4586ce4db..5c0d65bb1 100644 --- a/extern/sector-storage/selector_task.go +++ b/extern/sector-storage/selector_task.go @@ -42,7 +42,7 @@ func (s *taskSelector) Cmp(ctx context.Context, _ sealtasks.TaskType, a, b *work return len(atasks) < len(btasks), nil // prefer workers which can do less } - return a.active.utilization(a.info.Resources) < b.active.utilization(b.info.Resources), nil + return a.utilization() < b.utilization(), nil } var _ WorkerSelector = &allocSelector{}