Skip to content

Commit

Permalink
fix: reword score section in the scheduling framework
Browse files Browse the repository at this point in the history
  • Loading branch information
draveness committed Aug 19, 2019
1 parent 5bfa707 commit 3cbd7d5
Showing 1 changed file with 12 additions and 40 deletions.
52 changes: 12 additions & 40 deletions keps/sig-scheduling/20180409-scheduling-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,12 @@ each node.
the scheduler computes a final ranking of Nodes, and each score plugin receives
scores given by the same plugin to all nodes in "normalize scoring" phase.
`NormalizeScore` is called once per plugin per scheduling cycle right after
"score" phase. After the "normalize scoring" phase, it will return a well defined
range of integers `[0, 100]`, the scheduler will combine node scores from all
plugins according to the configured plugin weights.
"score" phase.

The output of a score plugin must be an integer in range of
**[NodeScoreMin, NodeScoreMax]**. if not, the scheduling cycle is aborted.
This is the output after running the optional NormalizeScore function of the
plugin. If NormalizeScore is not provided, the output of Score must be in this range

For example, suppose a plugin `BlinkingLightScorer` ranks Nodes based on how
many blinking lights they have.
Expand All @@ -223,50 +226,19 @@ However, the maximum count of blinking lights may be small compared to
`NodeScoreMax`. To fix this, `BlinkingLightScorer` should also implement `NormalizeScore`.

```go
func (*BlinkingLightScorer) NormalizeScore(pc *PluginContext, _ *v1.Pod, scores NodeScoreList) *Status {
func (*BlinkingLightScorer) NormalizeScore(pc *PluginContext, _ *v1.Pod, nodeScores NodeScoreList) *Status {
highest := 0
for _, score := range scores {
highest = max(highest, score)
for _, nodeScore := range nodeScores {
highest = max(highest, nodeScore.Score)
}
for node, score := range scores {
scores[node] = score*NodeScoreMax/highest
for i, nodeScore := range nodeScores {
nodeScores[i].Score = nodeScore.Score*NodeScoreMax/highest
}
return nil
}
```

If `NormalizeScore` returns an error, the scheduling cycle is aborted. The
scheduler would use a default normalize score strategy if the user does not
provide one.

```go
func DefaultNormalizeScore(pc *PluginContext, scores NodeScoreList) {
minScore := math.MinInt
maxScore := math.MaxInt

for _, score := range scores {
if minScore > score {
minScore = score
}

if maxScore < score {
maxScore = score
}
}

diff := maxScore - minScore
if diff == 0 {
for i := range scores {
scores[i] = 0
}
return
}

for i, score := range scores {
scores[i] = 100 * (score-minScore) / diff
}
}
```
If `NormalizeScore` returns an error, the scheduling cycle is aborted.

**Note:** Plugins wishing to perform "pre-reserve" work should use the `NormalizeScore` in the
scoring extension point.
Expand Down

0 comments on commit 3cbd7d5

Please sign in to comment.