-
Notifications
You must be signed in to change notification settings - Fork 6
/
trainingjob_list.go
39 lines (33 loc) · 1.03 KB
/
trainingjob_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package autoscaler
import (
padv1 "github.com/baidu/paddle-on-k8s-operator/pkg/apis/paddlepaddle/v1alpha1"
)
type trainingjobList []*padv1.TrainingJob
func (ts trainingjobList) Len() int {
return len(ts)
}
func (ts trainingjobList) Swap(a, b int) {
ts[a], ts[b] = ts[b], ts[a]
}
func (ts trainingjobList) Less(a, b int) bool {
scoreA := ts[a].Fulfillment()
scoreB := ts[b].Fulfillment()
if scoreA == scoreB {
resA := ts[a].Spec.Trainer.Resources
resB := ts[b].Spec.Trainer.Resources
resALimitsGPU := *resA.Limits.NvidiaGPU()
resBLimitsGPU := *resB.Limits.NvidiaGPU()
if resALimitsGPU.Cmp(resBLimitsGPU) == 0 {
resARequestsCPU := *resA.Requests.Cpu()
resBRequestsCPU := *resB.Requests.Cpu()
if resARequestsCPU.Cmp(resBRequestsCPU) == 0 {
resARequestsMem := *resA.Requests.Memory()
resBRequestsMem := *resB.Requests.Memory()
return resARequestsMem.Cmp(resBRequestsMem) == -1
}
return resARequestsCPU.Cmp(resBRequestsCPU) == -1
}
return resALimitsGPU.Cmp(resBLimitsGPU) == -1
}
return scoreA < scoreB
}