1
0
mirror of https://github.com/newnius/YAO-scheduler.git synced 2025-06-07 14:21:55 +00:00
This commit is contained in:
Newnius 2020-06-11 00:08:42 +08:00
parent 5874832309
commit 6b42565609

View File

@ -63,7 +63,7 @@ type ResourcePool struct {
enablePreScheduleRatio float64 enablePreScheduleRatio float64
enableBatch bool enableBatch bool
batchJobs []Job batchJobs map[string]Job
batchMu sync.Mutex batchMu sync.Mutex
batchAllocations map[string][]NodeStatus batchAllocations map[string][]NodeStatus
} }
@ -90,6 +90,7 @@ func (pool *ResourcePool) init(conf Configuration) {
pool.enableBatch = false pool.enableBatch = false
pool.batchAllocations = map[string][]NodeStatus{} pool.batchAllocations = map[string][]NodeStatus{}
pool.batchJobs = map[string]Job{}
/* init pools */ /* init pools */
pool.poolsCount = 300 pool.poolsCount = 300
@ -149,9 +150,11 @@ func (pool *ResourcePool) init(conf Configuration) {
} }
nodes = pool.doAcquireResource(job) nodes = pool.doAcquireResource(job)
if len(nodes) == 0 { if len(nodes) == 0 {
left = append(left, pool.batchJobs[0]) for jobName := range pool.batchJobs {
pool.batchJobs = pool.batchJobs[1:] left = append(left, pool.batchJobs[jobName])
log.Info("cannot find a valid allocation, remove a job randomly: ", left[len(left)-1].Name) delete(pool.batchJobs, jobName)
log.Info("cannot find a valid allocation, remove a job randomly: ", jobName)
}
continue continue
} }
for i, task := range job.Tasks { for i, task := range job.Tasks {
@ -162,7 +165,9 @@ func (pool *ResourcePool) init(conf Configuration) {
} }
//bug //bug
} }
pool.batchJobs = left for _, job := range left {
delete(pool.batchJobs, job.Name)
}
pool.batchMu.Unlock() pool.batchMu.Unlock()
} }
}() }()
@ -692,7 +697,7 @@ func (pool *ResourcePool) acquireResource(job Job) []NodeStatus {
return pool.doAcquireResource(job) return pool.doAcquireResource(job)
} }
pool.batchMu.Lock() pool.batchMu.Lock()
pool.batchJobs = append(pool.batchJobs, job) pool.batchJobs[job.Name] = job
pool.batchMu.Unlock() pool.batchMu.Unlock()
for { for {
if _, ok := pool.batchAllocations[job.Name]; ok { if _, ok := pool.batchAllocations[job.Name]; ok {