1
0
mirror of https://github.com/newnius/YAO-scheduler.git synced 2025-12-13 07:46:43 +00:00

add switcher for schduler

This commit is contained in:
2020-04-13 18:26:40 +08:00
parent 533099c14b
commit 301071fc87
5 changed files with 43 additions and 3 deletions

View File

@@ -21,4 +21,14 @@ GPU is occupied by which job(s)
``` ```
?action=get_bindings ?action=get_bindings
```
**EnableSchedule**
```
?action=debug_enable
```
**DisableSchedule**
```
?action=debug_disable
``` ```

View File

@@ -41,14 +41,14 @@ func (jhl *JobHistoryLogger) submitJob(job Job) {
} }
func (jhl *JobHistoryLogger) updateJobStatus(jobName string, state State) { func (jhl *JobHistoryLogger) updateJobStatus(jobName string, state State) {
log.Info("update job status", jobName) log.Debug("update job status", jobName)
if job, ok := jhl.jobs[jobName]; ok { if job, ok := jhl.jobs[jobName]; ok {
job.Status = state job.Status = state
} }
} }
func (jhl *JobHistoryLogger) submitTaskStatus(jobName string, task TaskStatus) { func (jhl *JobHistoryLogger) submitTaskStatus(jobName string, task TaskStatus) {
log.Info("submit job task status", jobName) log.Debug("submit job task status", jobName)
if tasks, ok := jhl.tasks[jobName]; ok { if tasks, ok := jhl.tasks[jobName]; ok {
jhl.tasks[jobName] = append(tasks, task) jhl.tasks[jobName] = append(tasks, task)
} }

View File

@@ -166,6 +166,20 @@ func serverAPI(w http.ResponseWriter, r *http.Request) {
w.Write(js) w.Write(js)
break break
case "debug_enable":
log.Debug("enable schedule")
js, _ := json.Marshal(scheduler.Enable)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
case "debug_disable":
log.Debug("disable schedule")
js, _ := json.Marshal(scheduler.Disable)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
break
default: default:
http.Error(w, "Not Found", http.StatusNotFound) http.Error(w, "Not Found", http.StatusNotFound)
break break

View File

@@ -28,4 +28,8 @@ type Scheduler interface {
Attach(GPU string, job string) Attach(GPU string, job string)
Detach(GPU string, job string) Detach(GPU string, job string)
Enable()
Disable()
} }

View File

@@ -22,6 +22,7 @@ type SchedulerFair struct {
jobs map[string]*JobManager jobs map[string]*JobManager
nextQueue string nextQueue string
resourceAllocations map[string]*ResourceCount resourceAllocations map[string]*ResourceCount
enabled bool
} }
type FairJobSorter []Job type FairJobSorter []Job
@@ -48,6 +49,9 @@ func (scheduler *SchedulerFair) Start() {
for { for {
log.Debug("Scheduling") log.Debug("Scheduling")
time.Sleep(time.Millisecond * 100) time.Sleep(time.Millisecond * 100)
if !scheduler.enabled {
continue
}
scheduler.scheduling.Lock() scheduler.scheduling.Lock()
scheduler.mu.Lock() scheduler.mu.Lock()
queue := scheduler.nextQueue queue := scheduler.nextQueue
@@ -207,7 +211,7 @@ func (scheduler *SchedulerFair) ReleaseResource(job Job, agent NodeStatus) {
if gpu.UUID == nodes.Status[j].UUID { if gpu.UUID == nodes.Status[j].UUID {
nodes.Status[j].MemoryAllocated -= gpu.MemoryTotal nodes.Status[j].MemoryAllocated -= gpu.MemoryTotal
if nodes.Status[j].MemoryAllocated < 0 { if nodes.Status[j].MemoryAllocated < 0 {
// in case error // in case of error
nodes.Status[j].MemoryAllocated = 0 nodes.Status[j].MemoryAllocated = 0
} }
} }
@@ -381,3 +385,11 @@ func (scheduler *SchedulerFair) Attach(GPU string, job string) {
func (scheduler *SchedulerFair) Detach(GPU string, job string) { func (scheduler *SchedulerFair) Detach(GPU string, job string) {
pool.detach(GPU, job) pool.detach(GPU, job)
} }
func (scheduler *SchedulerFair) Enable() {
scheduler.enabled = true
}
func (scheduler *SchedulerFair) Disable() {
scheduler.enabled = false
}