Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize NormalizeScore for PodTopologySpread #95809

Merged
merged 2 commits into from Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 4 additions & 10 deletions pkg/scheduler/framework/plugins/podtopologyspread/scoring.go
Expand Up @@ -30,6 +30,7 @@ import (
)

const preScoreStateKey = "PreScore" + Name
const invalidScore = -1

// preScoreState computed at PreScore and used at Score.
// Fields are exported for comparison during testing.
Expand Down Expand Up @@ -219,9 +220,10 @@ func (pl *PodTopologySpread) NormalizeScore(ctx context.Context, cycleState *fra
// Calculate <minScore> and <maxScore>
var minScore int64 = math.MaxInt64
var maxScore int64
for _, score := range scores {
for i, score := range scores {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing for i, score := range scores would make a copy of score for each element -- does for i := range score do better? kinda premature optimisation, but worth a quick check :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object is so small that it doesn't really matter.

// it's mandatory to check if <score.Name> is present in m.IgnoredNodes
if s.IgnoredNodes.Has(score.Name) {
scores[i].Score = invalidScore
alculquicondor marked this conversation as resolved.
Show resolved Hide resolved
continue
}
if score.Score < minScore {
Expand All @@ -233,22 +235,14 @@ func (pl *PodTopologySpread) NormalizeScore(ctx context.Context, cycleState *fra
}

for i := range scores {
nodeInfo, err := pl.sharedLister.NodeInfos().Get(scores[i].Name)
if err != nil {
return framework.AsStatus(err)
}
node := nodeInfo.Node()

if s.IgnoredNodes.Has(node.Name) {
if scores[i].Score == invalidScore {
scores[i].Score = 0
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and check it as this,

if scores[i].Score == 0 {
    continue
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The score coming from Score function is basically a counter. If that counter is zero, it should actually get the highest score. See how the value is reversed in the following lines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got you, thanks for the explanation.


if maxScore == 0 {
scores[i].Score = framework.MaxNodeScore
continue
}

s := scores[i].Score
scores[i].Score = framework.MaxNodeScore * (maxScore + minScore - s) / maxScore
}
Expand Down
Expand Up @@ -807,6 +807,11 @@ var (
existingPodsNum: 10000,
allNodesNum: 1000,
},
{
name: "5000nodes",
existingPodsNum: 50000,
allNodesNum: 5000,
},
}
)

Expand Down