From b2d441d2bb83fd5ab62e38c9d926a48629dabe36 Mon Sep 17 00:00:00 2001 From: Jun Gong Date: Tue, 19 Mar 2019 09:25:51 +0800 Subject: [PATCH] Preempt lowest priority task first --- pkg/scheduler/actions/preempt/preempt.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/scheduler/actions/preempt/preempt.go b/pkg/scheduler/actions/preempt/preempt.go index c6bb3f29a..78ddb5eda 100644 --- a/pkg/scheduler/actions/preempt/preempt.go +++ b/pkg/scheduler/actions/preempt/preempt.go @@ -220,8 +220,15 @@ func preempt( continue } - // Preempt victims for tasks. - for _, preemptee := range victims { + victimsQueue := util.NewPriorityQueue(func(l, r interface{}) bool { + return !ssn.TaskOrderFn(l, r) + }) + for _, victim := range victims { + victimsQueue.Push(victim) + } + // Preempt victims for tasks, pick lowest priority task first. + for !victimsQueue.Empty() { + preemptee := victimsQueue.Pop().(*api.TaskInfo) glog.Errorf("Try to preempt Task <%s/%s> for Tasks <%s/%s>", preemptee.Namespace, preemptee.Name, preemptor.Namespace, preemptor.Name) if err := stmt.Evict(preemptee, "preempt"); err != nil {