Skip to content

Commit 8592098

Browse files
authored
Merge pull request kubernetes#74974 from goodluckbot/pick-node-preempt-start-time
Pick node for preemption based on start time of pods
2 parents fcf21a2 + 8d991e6 commit 8592098

File tree

4 files changed

+189
-50
lines changed

4 files changed

+189
-50
lines changed

pkg/scheduler/core/generic_scheduler.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,8 @@ func EqualPriorityMap(_ *v1.Pod, _ interface{}, nodeInfo *schedulernodeinfo.Node
803803
// 2. A node with minimum highest priority victim is picked.
804804
// 3. Ties are broken by sum of priorities of all victims.
805805
// 4. If there are still ties, node with the minimum number of victims is picked.
806-
// 5. If there are still ties, the first such node is picked (sort of randomly).
806+
// 5. If there are still ties, node with the latest start time of all highest priority victims is picked.
807+
// 6. If there are still ties, the first such node is picked (sort of randomly).
807808
// The 'minNodes1' and 'minNodes2' are being reused here to save the memory
808809
// allocation and garbage collection time.
809810
func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*schedulerapi.Victims) *v1.Node {
@@ -902,11 +903,44 @@ func pickOneNodeForPreemption(nodesToVictims map[*v1.Node]*schedulerapi.Victims)
902903
lenNodes2++
903904
}
904905
}
906+
if lenNodes2 == 1 {
907+
return minNodes2[0]
908+
}
909+
910+
// There are a few nodes with same number of pods.
911+
// Find the node that satisfies latest(earliestStartTime(all highest-priority pods on node))
912+
latestStartTime := util.GetEarliestPodStartTime(nodesToVictims[minNodes2[0]])
913+
if latestStartTime == nil {
914+
// If the earliest start time of all pods on the 1st node is nil, just return it,
915+
// which is not expected to happen.
916+
klog.Errorf("earliestStartTime is nil for node %s. Should not reach here.", minNodes2[0])
917+
return minNodes2[0]
918+
}
919+
lenNodes1 = 0
920+
for i := 0; i < lenNodes2; i++ {
921+
node := minNodes2[i]
922+
// Get earliest start time of all pods on the current node.
923+
earliestStartTimeOnNode := util.GetEarliestPodStartTime(nodesToVictims[node])
924+
if earliestStartTimeOnNode == nil {
925+
klog.Errorf("earliestStartTime is nil for node %s. Should not reach here.", node)
926+
continue
927+
}
928+
if earliestStartTimeOnNode.After(latestStartTime.Time) {
929+
latestStartTime = earliestStartTimeOnNode
930+
lenNodes1 = 0
931+
}
932+
if earliestStartTimeOnNode.Equal(latestStartTime) {
933+
minNodes1[lenNodes1] = node
934+
lenNodes1++
935+
}
936+
}
937+
905938
// At this point, even if there are more than one node with the same score,
906939
// return the first one.
907-
if lenNodes2 > 0 {
908-
return minNodes2[0]
940+
if lenNodes1 > 0 {
941+
return minNodes1[0]
909942
}
943+
910944
klog.Errorf("Error in logic of node scoring for preemption. We should never reach here!")
911945
return nil
912946
}

0 commit comments

Comments
 (0)