Skip to content

Commit a0e3209

Browse files
committed
- updated scorer interface comment to mention constraint on scores
- normalization in kvcache-aware-scorer Signed-off-by: Maroon Ayoub <maroonay@gmail.com>
1 parent 84bbf6c commit a0e3209

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/epp/scheduling/plugins/scorers/kvcache-aware-scorer.go

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"math"
2324
"os"
2425
"time"
2526

@@ -111,11 +112,33 @@ func (s *KVCacheAwareScorer) Score(ctx *types.Context, pod types.Pod) (float64,
111112

112113
// update the cache
113114
s.scoresCache = make(map[string]float64, len(scores))
115+
minScore := math.MaxFloat64
116+
maxScore := 0.0
114117
for _, pod := range scores {
115118
s.scoresCache[pod.Name] = pod.Score
119+
120+
// maintain min and max to normalize later
121+
if pod.Score < minScore {
122+
minScore = pod.Score
123+
}
124+
125+
if pod.Score > maxScore {
126+
maxScore = pod.Score
127+
}
116128
}
129+
// normalize scores
130+
s.scoresCache = normalizeScores(s.scoresCache, minScore, maxScore)
131+
117132
s.scoresCacheLastUpdate = time.Now()
118133
loggerDebug.Info("Updated scores cache", "time", s.scoresCacheLastUpdate, "pods", s.scoresCache)
119134

120135
return s.scoresCache[pod.GetPod().Address], nil
121136
}
137+
138+
func normalizeScores(scores map[string]float64, minScore, maxScore float64) map[string]float64 {
139+
normalizedScores := make(map[string]float64, len(scores))
140+
for podName, score := range scores {
141+
normalizedScores[podName] = (score - minScore) / (maxScore - minScore)
142+
}
143+
return normalizedScores
144+
}

pkg/epp/scheduling/types/interfaces.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type Filter interface {
6363
}
6464

6565
// Scorer defines the interface for scoring pods based on context.
66+
// Scorers must return a score between 0 and 1, where 1 is the best score.
6667
type Scorer interface {
6768
Plugin
6869
Score(ctx *Context, pod Pod) (float64, error)

0 commit comments

Comments
 (0)