From acdbd39a0888719f787619462004732f0d1fd4d1 Mon Sep 17 00:00:00 2001 From: Newnius Date: Sun, 12 Apr 2020 11:13:23 +0800 Subject: [PATCH] add optimizer --- src/resource_pool.go | 33 ++++++++++++++++++++++++++++----- src/scheduler_fair.go | 2 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/resource_pool.go b/src/resource_pool.go index 45cec1b..6d86eca 100644 --- a/src/resource_pool.go +++ b/src/resource_pool.go @@ -28,6 +28,7 @@ type ResourcePool struct { counterTotal int bindings map[string]map[string]bool + utils map[string][]int } func (pool *ResourcePool) start() { @@ -111,6 +112,16 @@ func (pool *ResourcePool) update(node NodeStatus) { pool.mu.Lock() defer pool.mu.Unlock() + go func(node NodeStatus) { + for _, gpu := range node.Status { + if _, ok := pool.bindings[gpu.UUID]; ok { + if len(pool.bindings[gpu.UUID]) == 1 { + pool.utils[gpu.UUID] = append(pool.utils[gpu.UUID], gpu.UtilizationGPU) + } + } + } + }(node) + pool.heartBeat[node.ClientID] = time.Now() pool.counterTotal++ @@ -198,17 +209,29 @@ func (pool *ResourcePool) releaseNetwork(network string) { } func (pool *ResourcePool) attach(GPU string, job string) { + if _, ok := pool.bindings[GPU]; !ok { + pool.bindings[GPU] = map[string]bool{} + } + pool.bindings[GPU][job] = true + + if _, ok := pool.utils[GPU]; !ok { + pool.utils[GPU] = []int{} + } +} + +func (pool *ResourcePool) detach(GPU string, jobName string) { if _, ok := pool.bindings[GPU]; ok { - pool.bindings[GPU][job] = true + if len(pool.bindings[GPU]) == 1 { + InstanceOptimizer().feed(jobName, pool.utils[GPU]) + pool.utils[GPU] = []int{} + } } -} -func (pool *ResourcePool) detach(GPU string, job string) { if list, ok := pool.bindings[GPU]; ok { - delete(list, job) + delete(list, jobName) } } -func (pool *ResourcePool) getBindings() map[string]map[string]bool{ +func (pool *ResourcePool) getBindings() map[string]map[string]bool { return pool.bindings } \ No newline at end of file diff --git a/src/scheduler_fair.go b/src/scheduler_fair.go index cb752ea..44a5efe 100644 --- a/src/scheduler_fair.go +++ b/src/scheduler_fair.go @@ -47,7 +47,7 @@ func (scheduler *SchedulerFair) Start() { go func() { for { log.Debug("Scheduling") - time.Sleep(time.Second * 5) + time.Sleep(time.Millisecond * 100) scheduler.scheduling.Lock() scheduler.mu.Lock() queue := scheduler.nextQueue