From 5b84e1ea57d1ca99069937b2e8e716c47b997eeb Mon Sep 17 00:00:00 2001 From: Panos Woo Date: Mon, 15 Apr 2024 03:07:30 +0000 Subject: [PATCH] put back the queue to priority queue after job's resource allocating finished Signed-off-by: Panos Woo --- pkg/scheduler/actions/allocate/allocate.go | 7 ++- .../actions/allocate/allocate_test.go | 55 ++++++++++++++++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/pkg/scheduler/actions/allocate/allocate.go b/pkg/scheduler/actions/allocate/allocate.go index 888c10dc9a..4e62f534dc 100644 --- a/pkg/scheduler/actions/allocate/allocate.go +++ b/pkg/scheduler/actions/allocate/allocate.go @@ -151,9 +151,6 @@ func (alloc *Action) allocateResources(queues *util.PriorityQueue, jobsMap map[a } tasks := pendingTasks[job.UID] - // Added Queue back until no job in Namespace. - queues.Push(queue) - if tasks.Empty() { continue } @@ -162,6 +159,10 @@ func (alloc *Action) allocateResources(queues *util.PriorityQueue, jobsMap map[a tasks.Len(), job.Namespace, job.Name) alloc.allocateResourcesForTasks(tasks, job, jobs, queue, allNodes) + + // Put back the queue to priority queue after job's resource allocating finished, + // To ensure that the priority of the queue is calculated based on the latest resource allocation situation. + queues.Push(queue) } } diff --git a/pkg/scheduler/actions/allocate/allocate_test.go b/pkg/scheduler/actions/allocate/allocate_test.go index 3aff6b8895..5936009db7 100644 --- a/pkg/scheduler/actions/allocate/allocate_test.go +++ b/pkg/scheduler/actions/allocate/allocate_test.go @@ -133,9 +133,61 @@ func TestAllocate(t *testing.T) { }, BindsNum: 1, }, + { + Name: "high priority queue should allocate first", + PodGroups: []*schedulingv1.PodGroup{ + util.BuildPodGroup("pg-small-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupRunning), + util.BuildPodGroup("pg-large-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupInqueue), + util.BuildPodGroup("pg-large-2", "ns-1", "q-2", 0, nil, schedulingv1.PodGroupInqueue), + }, + Pods: []*v1.Pod{ + util.BuildPod("ns-1", "pod-small-1", "node-1", v1.PodRunning, api.BuildResourceList("1", "1G"), "pg-small-1", make(map[string]string), make(map[string]string)), + util.BuildPod("ns-1", "pod-large-1", "", v1.PodPending, api.BuildResourceList("2", "2G"), "pg-large-1", make(map[string]string), make(map[string]string)), + util.BuildPod("ns-1", "pod-large-2", "", v1.PodPending, api.BuildResourceList("3", "2G"), "pg-large-2", make(map[string]string), make(map[string]string)), + }, + Nodes: []*v1.Node{ + util.BuildNode("node-1", api.BuildResourceList("5", "5G", []api.ScalarResource{{Name: "pods", Value: "10"}}...), make(map[string]string)), + }, + Queues: []*schedulingv1.Queue{ + util.BuildQueue("q-1", 1, nil), + util.BuildQueue("q-2", 1, nil), + }, + Bind: map[string]string{ + "ns-1/pod-large-2": "node-1", + }, + BindsNum: 1, + }, + { + Name: "queue’s priority should be updated before it is put back into the priority queue", + PodGroups: []*schedulingv1.PodGroup{ + util.BuildPodGroup("pg-small-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupRunning), + util.BuildPodGroup("pg-large-1", "ns-1", "q-1", 0, nil, schedulingv1.PodGroupInqueue), + util.BuildPodGroup("pg-small-2", "ns-1", "q-2", 0, nil, schedulingv1.PodGroupInqueue), + util.BuildPodGroup("pg-large-2", "ns-1", "q-2", 0, nil, schedulingv1.PodGroupInqueue), + }, + Pods: []*v1.Pod{ + util.BuildPod("ns-1", "pod-small-1", "node-1", v1.PodRunning, api.BuildResourceList("1", "1G"), "pg-small-1", make(map[string]string), make(map[string]string)), + util.BuildPod("ns-1", "pod-large-1", "", v1.PodPending, api.BuildResourceList("2", "2G"), "pg-large-1", make(map[string]string), make(map[string]string)), + util.BuildPod("ns-1", "pod-large-2", "", v1.PodPending, api.BuildResourceList("2", "2G"), "pg-large-2", make(map[string]string), make(map[string]string)), + util.BuildPod("ns-1", "pod-small-2", "", v1.PodPending, api.BuildResourceList("1", "1G"), "pg-small-2", make(map[string]string), make(map[string]string)), + }, + Nodes: []*v1.Node{ + util.BuildNode("node-1", api.BuildResourceList("5", "5G", []api.ScalarResource{{Name: "pods", Value: "10"}}...), make(map[string]string)), + }, + Queues: []*schedulingv1.Queue{ + util.BuildQueue("q-1", 1, nil), + util.BuildQueue("q-2", 1, nil), + }, + Bind: map[string]string{ + "ns-1/pod-large-1": "node-1", + "ns-1/pod-large-2": "node-1", + }, + BindsNum: 2, + }, } trueValue := true + falseValue := false tiers := []conf.Tier{ { Plugins: []conf.PluginOption{ @@ -146,9 +198,10 @@ func TestAllocate(t *testing.T) { }, { Name: "proportion", + EnabledOverused: &falseValue, EnabledQueueOrder: &trueValue, EnabledReclaimable: &trueValue, - EnabledAllocatable: &trueValue, + EnabledAllocatable: &falseValue, }, { Name: predicates.PluginName,