diff --git a/pkg/scheduler/plugins/coscheduling/core/gang.go b/pkg/scheduler/plugins/coscheduling/core/gang.go index 0a7271d82..6e64a281e 100644 --- a/pkg/scheduler/plugins/coscheduling/core/gang.go +++ b/pkg/scheduler/plugins/coscheduling/core/gang.go @@ -390,12 +390,9 @@ func (gang *Gang) setScheduleCycleValid(valid bool) { if !valid && !gang.ScheduleCycleValid { /* - let's explain why by following example, there are three gang of one group: A, B and C, every gang group have min-member of 10 pod, noted as A1-A10, B1-B10, C1-C10. - 1. A1-A5 assumed in gangA scheduleCycle 1, B1-B5 assumed in gangA scheduleCycle 1, C1-C5 assumed in gangA scheduleCycle 1, C6 filter failed due to insufficient resource, then A6-10 failed due to cycle invalid, C7-C10 failed due to cycle invalid, B6-B9 failed due to cycle invalid - 2. A1-A5 assumed in gangA scheduleCycle 2, C1-C5 assumed in gangA scheduleCycle 2, C6 failed due to insufficient resource and gangA\B\C cycle set to invalid, - 3. then A6-A10,C7-C10 failed due to cycle invalid - 4. then B10 failed due to cycle invalid, B1 comes and find its gang scheduling cycle 2 can be valid, so it's assumed. - 5. however all it's sibling will come until next round of all gangs, these gangs will face insufficient resource due to pre-allocated of B10 + let's explain why by following example, there are three gang of one group: F, G, every gang group have min-member of 10 pod, noted as F1-F10, G1-G10. + 1. F1 failed due to insufficient resource, F2-F10 failed due to cycle invalid, + 2. then G1-G10 assumed, however all it's sibling will come until next round of all gangs, these gangs will face insufficient resource due to pre-allocated of G1-G10 TODO this logic can be optimized by give gangs of same group same scheduling cycle */ diff --git a/pkg/scheduler/plugins/coscheduling/coscheduling.go b/pkg/scheduler/plugins/coscheduling/coscheduling.go index 46531cf3f..0768cbd2f 100644 --- a/pkg/scheduler/plugins/coscheduling/coscheduling.go +++ b/pkg/scheduler/plugins/coscheduling/coscheduling.go @@ -140,20 +140,15 @@ func (cs *Coscheduling) Less(podInfo1, podInfo2 *framework.QueuedPodInfo) bool { } gangId1 := util.GetId(podInfo1.Pod.Namespace, util.GetGangNameByPod(podInfo1.Pod)) gangId2 := util.GetId(podInfo2.Pod.Namespace, util.GetGangNameByPod(podInfo2.Pod)) - // for member gang of same gangGroup, the gang that haven’t been satisfied yet take precedence + if gangId1 != gangId2 { - isGang1Satisfied := cs.pgMgr.IsGangMinSatisfied(podInfo1.Pod) - isGang2Satisfied := cs.pgMgr.IsGangMinSatisfied(podInfo2.Pod) - if isGang1Satisfied != isGang2Satisfied { - return !isGang1Satisfied - } - } else { - // for member pod of same gang, the pod with the smaller scheduling cycle take precedence so that gang scheduling cycle can be valid and iterated - childScheduleCycle1 := cs.pgMgr.GetChildScheduleCycle(podInfo1.Pod) - childScheduleCycle2 := cs.pgMgr.GetChildScheduleCycle(podInfo2.Pod) - if childScheduleCycle1 != childScheduleCycle2 { - return childScheduleCycle1 < childScheduleCycle2 - } + return gangId1 < gangId2 + } + // for member pod of same gang, the pod with the smaller scheduling cycle take precedence so that gang scheduling cycle can be valid and iterated + childScheduleCycle1 := cs.pgMgr.GetChildScheduleCycle(podInfo1.Pod) + childScheduleCycle2 := cs.pgMgr.GetChildScheduleCycle(podInfo2.Pod) + if childScheduleCycle1 != childScheduleCycle2 { + return childScheduleCycle1 < childScheduleCycle2 } return podInfo1.Timestamp.Before(podInfo2.Timestamp) } diff --git a/pkg/scheduler/plugins/coscheduling/coscheduling_test.go b/pkg/scheduler/plugins/coscheduling/coscheduling_test.go index a36460905..69ca46808 100644 --- a/pkg/scheduler/plugins/coscheduling/coscheduling_test.go +++ b/pkg/scheduler/plugins/coscheduling/coscheduling_test.go @@ -915,7 +915,7 @@ func TestFairness(t *testing.T) { "gangJ": {"default/gangH", "default/gangI", "default/gangJ"}, } gangMinRequiredNums := []int{20, 10, 32, 20, 20, 18, 43, 20, 30, 20} - gangInjectFilterError := []bool{false, false, true, false, false, true, true, false, false, true} + gangInjectFilterError := []bool{false, false, true, false, false, true, false, false, false, true} var gangInjectFilterErrorIndex []int for _, gangMinRequiredNum := range gangMinRequiredNums { gangInjectFilterErrorIndex = append(gangInjectFilterErrorIndex, rand.Intn(gangMinRequiredNum)) @@ -996,8 +996,8 @@ func TestFairness(t *testing.T) { ctx.Done(), scheduler.WithProfiles(cfg.Profiles...), scheduler.WithFrameworkOutOfTreeRegistry(registry), - scheduler.WithPodInitialBackoffSeconds(1), - scheduler.WithPodMaxBackoffSeconds(1), + scheduler.WithPodInitialBackoffSeconds(0), + scheduler.WithPodMaxBackoffSeconds(0), scheduler.WithPodMaxInUnschedulablePodsDuration(0), ) assert.NoError(t, err)