fix scoring algorithm when min count == current count
This commit is contained in:
parent
bad075f640
commit
7b0a27cad6
|
@ -135,6 +135,7 @@ func (iter *SpreadIterator) Next() *RankedNode {
|
|||
// The desired count for this attribute is zero if it gets here
|
||||
// so use the maximum possible penalty for this node
|
||||
totalSpreadScore += -1.0
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,22 +192,18 @@ func evenSpreadScoreBoost(pset *propertySet, option *structs.Node) float64 {
|
|||
delta := int(minCount - currentAttributeCount)
|
||||
deltaBoost = float64(delta) / float64(minCount)
|
||||
}
|
||||
if currentAttributeCount < minCount {
|
||||
// positive boost for attributes with min count
|
||||
return deltaBoost
|
||||
} else if currentAttributeCount > minCount {
|
||||
// Negative boost if attribute count is greater than minimum
|
||||
if currentAttributeCount != minCount {
|
||||
// Boost based on delta between current and min
|
||||
return deltaBoost
|
||||
} else {
|
||||
// When min and current value are the same we return the maximum
|
||||
// possible boost or penalty
|
||||
if minCount == maxCount {
|
||||
// Maximum possible penalty when the distribution is even
|
||||
return -1.0
|
||||
} else {
|
||||
// Maximum possible boost when there is another attribute with
|
||||
// more allocations
|
||||
return 1.0
|
||||
// Penalty based on delta from max value
|
||||
delta := int(maxCount - minCount)
|
||||
deltaBoost = float64(delta) / float64(minCount)
|
||||
return deltaBoost
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -286,7 +286,7 @@ func TestSpreadIterator_EvenSpread(t *testing.T) {
|
|||
"dc2": 0,
|
||||
}
|
||||
for _, rn := range out {
|
||||
require.Equal(t, expectedScores[rn.Node.Datacenter], rn.FinalScore)
|
||||
require.Equal(t, fmt.Sprintf("%.3f", expectedScores[rn.Node.Datacenter]), fmt.Sprintf("%.3f", rn.FinalScore))
|
||||
}
|
||||
|
||||
// Update the plan to add allocs to nodes in dc1
|
||||
|
@ -380,11 +380,11 @@ func TestSpreadIterator_EvenSpread(t *testing.T) {
|
|||
// Expect nodes in dc2 to be penalized because there are 3 allocs there now
|
||||
// dc1 nodes are boosted because that has 2 allocs
|
||||
expectedScores = map[string]float64{
|
||||
"dc1": 1,
|
||||
"dc1": 0.5,
|
||||
"dc2": -0.5,
|
||||
}
|
||||
for _, rn := range out {
|
||||
require.Equal(t, expectedScores[rn.Node.Datacenter], rn.FinalScore)
|
||||
require.Equal(t, fmt.Sprintf("%3.3f", expectedScores[rn.Node.Datacenter]), fmt.Sprintf("%3.3f", rn.FinalScore))
|
||||
}
|
||||
|
||||
// Add another node in dc3
|
||||
|
@ -427,7 +427,7 @@ func TestSpreadIterator_EvenSpread(t *testing.T) {
|
|||
"dc3": 1,
|
||||
}
|
||||
for _, rn := range out {
|
||||
require.Equal(t, expectedScores[rn.Node.Datacenter], rn.FinalScore)
|
||||
require.Equal(t, fmt.Sprintf("%.3f", expectedScores[rn.Node.Datacenter]), fmt.Sprintf("%.3f", rn.FinalScore))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue