Skip to content

Commit

Permalink
scheduler: modify coscheduling Less function with considering childSc…
Browse files Browse the repository at this point in the history
…heduleCycle (#1702)

Signed-off-by: xingbao.zy <[email protected]>
Co-authored-by: xingbao.zy <[email protected]>
  • Loading branch information
buptcozy and xingbao.zy authored Oct 9, 2023
1 parent 77f919d commit fc94295
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
10 changes: 10 additions & 0 deletions pkg/scheduler/plugins/coscheduling/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Manager interface {
GetGangSummary(gangId string) (*GangSummary, bool)
GetGangSummaries() map[string]*GangSummary
IsGangMinSatisfied(*corev1.Pod) bool
GetChildScheduleCycle(*corev1.Pod) int
}

// PodGroupManager defines the scheduling operation called
Expand Down Expand Up @@ -534,3 +535,12 @@ func (pgMgr *PodGroupManager) GetGangSummaries() map[string]*GangSummary {

return result
}

func (pgMgr *PodGroupManager) GetChildScheduleCycle(pod *corev1.Pod) int {
gang := pgMgr.GetGangByPod(pod)
if gang == nil {
return 0
}

return gang.getChildScheduleCycle(pod)
}
3 changes: 3 additions & 0 deletions pkg/scheduler/plugins/coscheduling/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ func TestPlugin_PreFilter(t *testing.T) {
assert.Equal(t, tt.expectedScheduleCycle, gang.getScheduleCycle())
assert.Equal(t, tt.expectedScheduleCycleValid, gang.isScheduleCycleValid())
assert.Equal(t, tt.expectedChildCycleMap, gang.ChildrenScheduleRoundMap)

assert.Equal(t, tt.expectedChildCycleMap[util.GetId(tt.pod.Namespace, tt.pod.Name)],
mgr.GetChildScheduleCycle(tt.pod))
}
})
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/scheduler/plugins/coscheduling/coscheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ func (cs *Coscheduling) Less(podInfo1, podInfo2 *framework.QueuedPodInfo) bool {
return !isgang1satisfied
}

childScheduleCycle1 := cs.pgMgr.GetChildScheduleCycle(podInfo1.Pod)
childScheduleCycle2 := cs.pgMgr.GetChildScheduleCycle(podInfo2.Pod)
if childScheduleCycle1 != childScheduleCycle2 {
return childScheduleCycle1 < childScheduleCycle2
}

creationTime1 := cs.pgMgr.GetCreatTime(podInfo1)
creationTime2 := cs.pgMgr.GetCreatTime(podInfo2)
if creationTime1.Equal(creationTime2) {
Expand Down
38 changes: 33 additions & 5 deletions pkg/scheduler/plugins/coscheduling/coscheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"testing"
"time"

"github.com/koordinator-sh/koordinator/pkg/scheduler/plugins/coscheduling/core"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -319,11 +321,13 @@ func TestLess(t *testing.T) {
}
time.Sleep(100 * time.Millisecond)
for _, tt := range []struct {
name string
p1 *framework.QueuedPodInfo
p2 *framework.QueuedPodInfo
annotations map[string]string
expected bool
name string
p1 *framework.QueuedPodInfo
p2 *framework.QueuedPodInfo
childScheduleCycle1 int
childScheduleCycle2 int
annotations map[string]string
expected bool
}{
{
name: "p1.priority less than p2.priority,but p1's subPriority is greater than p2's",
Expand Down Expand Up @@ -457,6 +461,20 @@ func TestLess(t *testing.T) {
},
expected: true, // p1 should be ahead of p2 in the queue
},
{
name: "equal priority and creation time, both belongs to gangB, childScheduleCycle not equal",
p1: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Namespace(gangB_ns).Name("pod1").Priority(highPriority).Label(v1alpha1.PodGroupLabel, "gangB").Obj()),
InitialAttemptTimestamp: lateTime,
},
p2: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Namespace(gangB_ns).Name("pod2").Priority(highPriority).Label(v1alpha1.PodGroupLabel, "gangB").Obj()),
InitialAttemptTimestamp: earltTime,
},
childScheduleCycle1: 2,
childScheduleCycle2: 1,
expected: false, // p1 should be ahead of p2 in the queue
},
{
name: "equal priority and creation time, p1 belongs to gangA that has been satisfied",
p1: &framework.QueuedPodInfo{
Expand All @@ -475,6 +493,16 @@ func TestLess(t *testing.T) {
if len(tt.annotations) != 0 {
tt.p1.Pod.Annotations = tt.annotations
}

gang1 := gp.pgMgr.(*core.PodGroupManager).GetGangByPod(tt.p1.Pod)
gang2 := gp.pgMgr.(*core.PodGroupManager).GetGangByPod(tt.p2.Pod)
if gang1 != nil {
gang1.ChildrenScheduleRoundMap[util.GetId(tt.p1.Pod.Namespace, tt.p1.Pod.Name)] = tt.childScheduleCycle1
}
if gang2 != nil {
gang2.ChildrenScheduleRoundMap[util.GetId(tt.p2.Pod.Namespace, tt.p2.Pod.Name)] = tt.childScheduleCycle2
}

if got := gp.Less(tt.p1, tt.p2); got != tt.expected {
t.Errorf("expected %v, got %v", tt.expected, got)
}
Expand Down

0 comments on commit fc94295

Please sign in to comment.