sched: Nicer handling of multicore tasks

This commit is contained in:
Łukasz Magiera 2020-04-27 14:38:24 +02:00
parent 2ef195583f
commit f59d6b971b
3 changed files with 10 additions and 16 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"io" "io"
"os" "os"
"runtime"
"github.com/elastic/go-sysinfo" "github.com/elastic/go-sysinfo"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -195,6 +196,7 @@ func (l *LocalWorker) Info(context.Context) (storiface.WorkerInfo, error) {
MemPhysical: mem.Total, MemPhysical: mem.Total,
MemSwap: mem.VirtualTotal, MemSwap: mem.VirtualTotal,
MemReserved: mem.VirtualUsed + mem.Total - mem.Available, // TODO: sub this process MemReserved: mem.VirtualUsed + mem.Total - mem.Available, // TODO: sub this process
CPUs: uint64(runtime.NumCPU()),
GPUs: gpus, GPUs: gpus,
}, },
}, nil }, nil

View File

@ -45,7 +45,7 @@ type workerHandle struct {
memUsedMin uint64 memUsedMin uint64
memUsedMax uint64 memUsedMax uint64
gpuUsed bool gpuUsed bool
cpuUse int // -1 - multicore thing; 0 - free; 1+ - singlecore things cpuUse uint64 // 0 - free; 1+ - singlecore things
} }
func (m *Manager) runSched() { func (m *Manager) runSched() {
@ -150,13 +150,9 @@ func (m *Manager) makeResponse(wid WorkerID, w *workerHandle, req *workerRequest
w.gpuUsed = needRes.CanGPU w.gpuUsed = needRes.CanGPU
if needRes.MultiThread { if needRes.MultiThread {
w.cpuUse = -1 w.cpuUse += w.info.Resources.CPUs
} else { } else {
if w.cpuUse != -1 {
w.cpuUse++ w.cpuUse++
} else {
log.Warnf("sched: makeResponse for worker %d: worker cpu is in multicore use, but a single core task was scheduled", wid)
}
} }
w.memUsedMin += needRes.MinMemory w.memUsedMin += needRes.MinMemory
@ -173,8 +169,8 @@ func (m *Manager) makeResponse(wid WorkerID, w *workerHandle, req *workerRequest
} }
if needRes.MultiThread { if needRes.MultiThread {
w.cpuUse = 0 w.cpuUse -= w.info.Resources.CPUs
} else if w.cpuUse != -1 { } else {
w.cpuUse-- w.cpuUse--
} }
@ -216,13 +212,8 @@ func (m *Manager) canHandleRequest(wid WorkerID, w *workerHandle, req *workerReq
} }
if needRes.MultiThread { if needRes.MultiThread {
if w.cpuUse != 0 { if w.cpuUse > 0 {
log.Debugf("sched: not scheduling on worker %d; multicore process needs free CPU", wid) log.Debugf("sched: not scheduling on worker %d; multicore process needs %d threads, %d in use, target %d", wid, res.CPUs, w.cpuUse, res.CPUs)
return false, nil
}
} else {
if w.cpuUse == -1 {
log.Debugf("sched: not scheduling on worker %d; CPU in use by a multicore process", wid)
return false, nil return false, nil
} }
} }

View File

@ -12,6 +12,7 @@ type WorkerResources struct {
MemReserved uint64 // Used by system / other processes MemReserved uint64 // Used by system / other processes
CPUs uint64 // Logical cores
GPUs []string GPUs []string
} }