optimize trySched
This commit is contained in:
parent
60e950015c
commit
3207bc4704
30
extern/sector-storage/sched.go
vendored
30
extern/sector-storage/sched.go
vendored
@ -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()
|
sh.workersLk.RLock()
|
||||||
defer sh.workersLk.RUnlock()
|
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
|
// nothing to schedule on
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
windows := make([]schedWindow, windowsLen)
|
||||||
|
acceptableWindows := make([][]int, queuneLen)
|
||||||
|
|
||||||
// Step 1
|
// Step 1
|
||||||
concurrency := len(sh.openWindows)
|
throttle := make(chan struct{}, windowsLen)
|
||||||
throttle := make(chan struct{}, concurrency)
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(sh.schedQueue.Len())
|
wg.Add(queuneLen)
|
||||||
|
for i := 0; i < queuneLen; i++ {
|
||||||
for i := 0; i < sh.schedQueue.Len(); i++ {
|
|
||||||
throttle <- struct{}{}
|
throttle <- struct{}{}
|
||||||
|
|
||||||
go func(sqi int) {
|
go func(sqi int) {
|
||||||
@ -417,9 +419,9 @@ func (sh *scheduler) trySched() {
|
|||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
scheduled := 0
|
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]
|
task := (*sh.schedQueue)[sqi]
|
||||||
needRes := ResourceTable[task.taskType][sh.spt]
|
needRes := ResourceTable[task.taskType][sh.spt]
|
||||||
|
|
||||||
@ -488,7 +490,7 @@ func (sh *scheduler) trySched() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite sh.openWindows array, removing scheduled windows
|
// 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 {
|
for wnd, window := range sh.openWindows {
|
||||||
if _, scheduled := scheduledWindows[wnd]; scheduled {
|
if _, scheduled := scheduledWindows[wnd]; scheduled {
|
||||||
// keep unscheduled windows open
|
// keep unscheduled windows open
|
||||||
|
Loading…
Reference in New Issue
Block a user