From f2dc2fe236a151f7d97bb8cd07e18d091e164e3d Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Tue, 24 Jul 2018 10:49:50 -0500 Subject: [PATCH] Some minor changes from code review --- scheduler/rank.go | 10 +++++----- scheduler/rank_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scheduler/rank.go b/scheduler/rank.go index f73ad0bcb4d..56620075332 100644 --- a/scheduler/rank.go +++ b/scheduler/rank.go @@ -309,7 +309,7 @@ func (iter *JobAntiAffinityIterator) Next() *RankedNode { // Calculate the penalty based on number of collisions // TODO(preetha): Figure out if batch jobs need a different scoring penalty where collisions matter less if collisions > 0 { - scorePenalty := -1 * float64(collisions) / float64(iter.desiredCount) + scorePenalty := -1 * float64(collisions+1) / float64(iter.desiredCount) option.Scores = append(option.Scores, scorePenalty) iter.ctx.Metrics().ScoreNode(option.Node, "job-anti-affinity", scorePenalty) } @@ -432,13 +432,13 @@ func (iter *NodeAffinityIterator) Next() *RankedNode { totalAffinityScore := 0.0 for _, affinity := range iter.affinities { if matchesAffinity(iter.ctx, affinity, option.Node) { - normScore := affinity.Weight / sumWeight - totalAffinityScore += normScore + totalAffinityScore += affinity.Weight } } + normScore := totalAffinityScore / sumWeight if totalAffinityScore != 0.0 { - option.Scores = append(option.Scores, totalAffinityScore) - iter.ctx.Metrics().ScoreNode(option.Node, "node-affinity", totalAffinityScore) + option.Scores = append(option.Scores, normScore) + iter.ctx.Metrics().ScoreNode(option.Node, "node-affinity", normScore) } return option } diff --git a/scheduler/rank_test.go b/scheduler/rank_test.go index 3af1d771bd8..7735e9aea3b 100644 --- a/scheduler/rank_test.go +++ b/scheduler/rank_test.go @@ -427,8 +427,8 @@ func TestJobAntiAffinity_PlannedAlloc(t *testing.T) { if out[0] != nodes[0] { t.Fatalf("Bad: %v", out) } - // Score should be -(#collissions/desired_count) => -(2/4) - if out[0].FinalScore != -0.5 { + // Score should be -(#collissions+1/desired_count) => -(3/4) + if out[0].FinalScore != -0.75 { t.Fatalf("Bad Score: %#v", out[0].FinalScore) } @@ -546,8 +546,8 @@ func TestScoreNormalizationIterator(t *testing.T) { require.Equal(2, len(out)) require.Equal(out[0], nodes[0]) // Score should be averaged between both scorers - // -0.5 from job anti affinity and -1 from node rescheduling penalty - require.Equal(out[0].FinalScore, -0.75) + // -0.75 from job anti affinity and -1 from node rescheduling penalty + require.Equal(-0.875, out[0].FinalScore) require.Equal(out[1], nodes[1]) require.Equal(out[1].FinalScore, 0.0) }