lotus/storage/sealer/sched_assigner_spread.go

82 lines
1.8 KiB
Go
Raw Normal View History

package sealer
import (
"math"
storiface "github.com/filecoin-project/lotus/storage/sealer/storiface"
)
2022-05-23 14:58:43 +00:00
func NewSpreadAssigner() Assigner {
2022-05-18 14:11:07 +00:00
return &AssignerCommon{
2022-05-23 14:58:43 +00:00
WindowSel: SpreadWS,
}
2022-05-18 14:11:07 +00:00
}
2022-05-23 14:58:43 +00:00
func SpreadWS(sh *Scheduler, queueLen int, acceptableWindows [][]int, windows []SchedWindow) int {
scheduled := 0
rmQueue := make([]int, 0, queueLen)
2022-05-23 14:58:43 +00:00
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
2022-05-23 14:58:43 +00:00
bestAssigned := math.MaxInt // smaller = better
for i, wnd := range acceptableWindows[task.IndexHeap] {
wid := sh.OpenWindows[wnd].Worker
w := sh.Workers[wid]
2022-05-23 20:18:41 +00:00
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)
if !windows[wnd].Allocated.CanHandleRequest(task.SealTask(), res, wid, "schedAssign", w.Info) {
continue
}
2022-05-23 14:58:43 +00:00
wu, _ := workerAssigned[wid]
if wu >= bestAssigned {
continue
}
info = w.Info
needRes = res
bestWid = wid
selectedWindow = wnd
2022-05-23 14:58:43 +00:00
bestAssigned = wu
}
if selectedWindow < 0 {
// all windows full
continue
}
log.Debugw("SCHED ASSIGNED",
"sqi", sqi,
"sector", task.Sector.ID.Number,
"task", task.TaskType,
"window", selectedWindow,
"worker", bestWid,
2022-05-23 14:58:43 +00:00
"assigned", bestAssigned)
2022-05-23 15:32:54 +00:00
workerAssigned[bestWid]++
windows[selectedWindow].Allocated.Add(task.SealTask(), info.Resources, needRes)
windows[selectedWindow].Todo = append(windows[selectedWindow].Todo, task)
rmQueue = append(rmQueue, sqi)
scheduled++
}
if len(rmQueue) > 0 {
for i := len(rmQueue) - 1; i >= 0; i-- {
sh.SchedQueue.Remove(rmQueue[i])
}
}
2022-05-18 14:11:07 +00:00
return scheduled
}