1
0
mirror of https://github.com/newnius/YAO-scheduler.git synced 2025-12-15 16:16:44 +00:00
Files
YAO-scheduler/src/ga_test.go

72 lines
1.6 KiB
Go
Raw Normal View History

2020-05-25 21:41:39 +08:00
package main
import (
"strconv"
"time"
2020-05-26 20:46:11 +08:00
log "github.com/sirupsen/logrus"
2020-05-25 21:41:39 +08:00
"testing"
)
2020-05-26 20:46:11 +08:00
func TgenerateCase() ([]NodeStatus, []Task) {
2020-05-27 19:12:17 +08:00
numTask := 6
2020-05-25 21:41:39 +08:00
2020-05-26 20:46:11 +08:00
var nodes []NodeStatus
var tasks []Task
2020-05-25 21:41:39 +08:00
2020-05-27 18:04:05 +08:00
for i := 0; i < numTask*3; i++ {
2020-05-26 20:46:11 +08:00
node := NodeStatus{ClientID: strconv.Itoa(i), Rack: "Rack-" + strconv.Itoa(i%40), Domain: "Domain-" + strconv.Itoa(i%4)}
2020-05-25 21:41:39 +08:00
node.NumCPU = 24
2020-05-26 20:46:11 +08:00
node.UtilCPU = 2.0
2020-05-25 21:41:39 +08:00
node.MemTotal = 188
2020-05-26 20:46:11 +08:00
node.MemAvailable = 20
2020-05-25 21:41:39 +08:00
node.TotalBW = 100
2020-05-27 18:04:05 +08:00
cnt := 4
2020-05-26 21:01:41 +08:00
//cnt := rand.Intn(3) + 1
2020-05-25 21:41:39 +08:00
for i := 0; i < cnt; i++ {
2020-05-26 20:46:11 +08:00
node.Status = append(node.Status, GPUStatus{MemoryTotal: 11439, MemoryAllocated: 0, UUID: node.ClientID + "-" + strconv.Itoa(i)})
2020-05-25 21:41:39 +08:00
}
2020-05-26 20:46:11 +08:00
nodes = append(nodes, node)
2020-05-25 21:41:39 +08:00
}
for i := 0; i < numTask; i++ {
isPS := false
2020-05-27 19:12:17 +08:00
if i < numTask/3 {
2020-05-25 21:41:39 +08:00
isPS = true
}
2020-05-26 20:46:11 +08:00
task := Task{Name: "task-" + strconv.Itoa(i), IsPS: isPS}
2020-05-25 21:41:39 +08:00
task.Memory = 4
task.NumberCPU = 2
task.NumberGPU = 1
2020-05-26 20:46:11 +08:00
task.MemoryGPU = 4096
tasks = append(tasks, task)
2020-05-25 21:41:39 +08:00
}
2020-05-26 20:46:11 +08:00
return nodes, tasks
}
2020-05-25 21:41:39 +08:00
2020-05-26 20:46:11 +08:00
func TestBestFit(t *testing.T) {
2020-05-27 18:04:05 +08:00
return
2020-05-26 20:46:11 +08:00
nodes, tasks := TgenerateCase()
for _, node := range nodes {
log.Info(node)
2020-05-25 21:41:39 +08:00
}
s := time.Now()
2020-05-27 18:04:05 +08:00
allocation := InstanceOfAllocator().fastBestFit(nodes, tasks)
2020-05-25 21:41:39 +08:00
log.Println(time.Since(s))
2020-05-26 20:46:11 +08:00
log.Println(allocation)
}
func TestGA(t *testing.T) {
2020-05-25 21:41:39 +08:00
2020-05-27 18:04:05 +08:00
nodes, tasks := TgenerateCase()
2020-05-26 20:46:11 +08:00
2020-05-27 18:04:05 +08:00
allocation := InstanceOfAllocator().GA(nodes, tasks, true)
2020-05-26 20:46:11 +08:00
2020-05-27 18:04:05 +08:00
log.Info(allocation.TasksOnNode)
log.Info(allocation.Nodes)
2020-05-26 20:46:11 +08:00
2020-05-27 18:04:05 +08:00
allocation = InstanceOfAllocator().fastBestFit(nodes, tasks)
2020-05-26 20:46:11 +08:00
2020-05-27 18:04:05 +08:00
InstanceOfResourcePool().init(Configuration{})
allocatedNodes := InstanceOfResourcePool().acquireResource(Job{Tasks: tasks})
log.Info(allocatedNodes)
2020-05-25 21:41:39 +08:00
}