2022-06-14 18:03:38 +00:00
|
|
|
package sealer
|
2022-05-18 13:47:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2022-05-18 13:47:08 +00:00
|
|
|
)
|
|
|
|
|
2023-02-27 16:44:38 +00:00
|
|
|
func NewSpreadAssigner(queued bool) Assigner {
|
2022-05-18 14:11:07 +00:00
|
|
|
return &AssignerCommon{
|
2023-02-27 16:44:38 +00:00
|
|
|
WindowSel: SpreadWS(queued),
|
2022-05-18 13:47:08 +00:00
|
|
|
}
|
2022-05-18 14:11:07 +00:00
|
|
|
}
|
2022-05-18 13:47:08 +00:00
|
|
|
|
2023-02-27 16:44:38 +00:00
|
|
|
func SpreadWS(queued bool) func(sh *Scheduler, queueLen int, acceptableWindows [][]int, windows []SchedWindow) int {
|
|
|
|
return func(sh *Scheduler, queueLen int, acceptableWindows [][]int, windows []SchedWindow) int {
|
|
|
|
scheduled := 0
|
|
|
|
rmQueue := make([]int, 0, queueLen)
|
|
|
|
workerAssigned := map[storiface.WorkerID]int{}
|
|
|
|
|
|
|
|
for sqi := 0; sqi < queueLen; sqi++ {
|
|
|
|
task := (*sh.SchedQueue)[sqi]
|
|
|
|
|
|
|
|
selectedWindow := -1
|
|
|
|
var needRes storiface.Resources
|
|
|
|
var info storiface.WorkerInfo
|
|
|
|
var bestWid storiface.WorkerID
|
|
|
|
bestAssigned := math.MaxInt // smaller = better
|
|
|
|
|
|
|
|
for i, wnd := range acceptableWindows[task.IndexHeap] {
|
|
|
|
wid := sh.OpenWindows[wnd].Worker
|
|
|
|
w := sh.Workers[wid]
|
|
|
|
|
|
|
|
res := w.Info.Resources.ResourceSpec(task.Sector.ProofType, task.TaskType)
|
|
|
|
|
|
|
|
log.Debugf("SCHED try assign sqi:%d sector %d to window %d (awi:%d)", sqi, task.Sector.ID.Number, wnd, i)
|
|
|
|
|
2023-05-10 19:43:42 +00:00
|
|
|
if !windows[wnd].Allocated.CanHandleRequest(task.SchedId, task.SealTask(), res, wid, "schedAssign", w.Info) {
|
2023-02-27 16:44:38 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
wu, found := workerAssigned[wid]
|
|
|
|
if !found && queued {
|
|
|
|
wu = w.TaskCounts()
|
|
|
|
workerAssigned[wid] = wu
|
|
|
|
}
|
|
|
|
if wu >= bestAssigned {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
info = w.Info
|
|
|
|
needRes = res
|
|
|
|
bestWid = wid
|
|
|
|
selectedWindow = wnd
|
|
|
|
bestAssigned = wu
|
2022-05-18 13:47:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 16:44:38 +00:00
|
|
|
if selectedWindow < 0 {
|
|
|
|
// all windows full
|
2022-05-23 14:58:43 +00:00
|
|
|
continue
|
2022-05-18 13:47:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 16:44:38 +00:00
|
|
|
log.Debugw("SCHED ASSIGNED",
|
|
|
|
"assigner", "spread",
|
|
|
|
"spread-queued", queued,
|
|
|
|
"sqi", sqi,
|
|
|
|
"sector", task.Sector.ID.Number,
|
|
|
|
"task", task.TaskType,
|
|
|
|
"window", selectedWindow,
|
|
|
|
"worker", bestWid,
|
|
|
|
"assigned", bestAssigned)
|
|
|
|
|
|
|
|
workerAssigned[bestWid]++
|
2023-05-10 19:43:42 +00:00
|
|
|
windows[selectedWindow].Allocated.Add(task.SchedId, task.SealTask(), info.Resources, needRes)
|
2023-02-27 16:44:38 +00:00
|
|
|
windows[selectedWindow].Todo = append(windows[selectedWindow].Todo, task)
|
|
|
|
|
|
|
|
rmQueue = append(rmQueue, sqi)
|
|
|
|
scheduled++
|
2022-05-18 13:47:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 16:44:38 +00:00
|
|
|
if len(rmQueue) > 0 {
|
|
|
|
for i := len(rmQueue) - 1; i >= 0; i-- {
|
|
|
|
sh.SchedQueue.Remove(rmQueue[i])
|
|
|
|
}
|
2022-05-18 13:47:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 16:44:38 +00:00
|
|
|
return scheduled
|
2022-05-18 13:47:08 +00:00
|
|
|
}
|
|
|
|
}
|