From 2143fa2ab7b7ec6d56aa8eaf1b0a90b96bea7f0a Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Thu, 27 Sep 2018 23:44:01 -0500 Subject: [PATCH] Use scheduler config from state store to enable/disable preemption --- scheduler/scheduler.go | 3 +++ scheduler/stack.go | 14 +++++++++----- scheduler/system_sched_test.go | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index b9f0f5e3a..bd921a788 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -88,6 +88,9 @@ type State interface { // LatestDeploymentByJobID returns the latest deployment matching the given // job ID LatestDeploymentByJobID(ws memdb.WatchSet, namespace, jobID string) (*structs.Deployment, error) + + // SchedulerConfig returns config options for the scheduler + SchedulerConfig() (uint64, *structs.SchedulerConfiguration, error) } // Planner interface is used to submit a task allocation plan. diff --git a/scheduler/stack.go b/scheduler/stack.go index 6be27c5e2..d9ae982b4 100644 --- a/scheduler/stack.go +++ b/scheduler/stack.go @@ -109,10 +109,9 @@ func NewGenericStack(batch bool, ctx Context) *GenericStack { rankSource := NewFeasibleRankIterator(ctx, s.distinctPropertyConstraint) // Apply the bin packing, this depends on the resources needed - // by a particular task group. Only enable eviction for the service - // scheduler as that logic is expensive. - evict := !batch - s.binPack = NewBinPackIterator(ctx, rankSource, evict, 0) + // by a particular task group. + + s.binPack = NewBinPackIterator(ctx, rankSource, false, 0) // Apply the job anti-affinity iterator. This is to avoid placing // multiple allocations on the same node for this job. @@ -287,7 +286,12 @@ func NewSystemStack(ctx Context) *SystemStack { // Apply the bin packing, this depends on the resources needed // by a particular task group. Enable eviction as system jobs are high // priority. - s.binPack = NewBinPackIterator(ctx, rankSource, true, 0) + _, schedConfig, _ := s.ctx.State().SchedulerConfig() + enablePreemption := false + if schedConfig != nil { + enablePreemption = schedConfig.EnablePreemption + } + s.binPack = NewBinPackIterator(ctx, rankSource, enablePreemption, 0) // Apply score normalization s.scoreNorm = NewScoreNormalizationIterator(ctx, s.binPack) diff --git a/scheduler/system_sched_test.go b/scheduler/system_sched_test.go index d2cf1f5f8..a190d113a 100644 --- a/scheduler/system_sched_test.go +++ b/scheduler/system_sched_test.go @@ -242,6 +242,9 @@ func TestSystemSched_ExhaustResources(t *testing.T) { node := mock.Node() noErr(t, h.State.UpsertNode(h.NextIndex(), node)) + // Enable Preemption + h.State.SchedulerSetConfig(h.NextIndex(), &structs.SchedulerConfiguration{EnablePreemption: true}) + // Create a service job which consumes most of the system resources svcJob := mock.Job() svcJob.TaskGroups[0].Count = 1 @@ -1573,6 +1576,9 @@ func TestSystemSched_Preemption(t *testing.T) { nodes = append(nodes, node) } + // Enable Preemption + h.State.SchedulerSetConfig(h.NextIndex(), &structs.SchedulerConfiguration{EnablePreemption: true}) + // Create some low priority batch jobs and allocations for them // One job uses a reserved port job1 := mock.BatchJob()