Improve performance of NodeResourcesFit scoring

Signed-off-by: tangwz <tangwz.com@gmail.com>
This commit is contained in:
tangwz
2022-12-10 02:11:27 +08:00
parent 4eb5821c51
commit a4ab559ba4
9 changed files with 219 additions and 68 deletions

View File

@@ -78,28 +78,25 @@ func NewBalancedAllocation(baArgs runtime.Object, h framework.Handle, fts featur
return nil, err
}
resToWeightMap := make(resourceToWeightMap)
for _, resource := range args.Resources {
resToWeightMap[v1.ResourceName(resource.Name)] = resource.Weight
}
return &BalancedAllocation{
handle: h,
resourceAllocationScorer: resourceAllocationScorer{
Name: BalancedAllocationName,
scorer: balancedResourceScorer,
useRequested: true,
resourceToWeightMap: resToWeightMap,
Name: BalancedAllocationName,
scorer: balancedResourceScorer,
useRequested: true,
resources: args.Resources,
},
}, nil
}
func balancedResourceScorer(requested, allocable resourceToValueMap) int64 {
func balancedResourceScorer(requested, allocable []int64) int64 {
var resourceToFractions []float64
var totalFraction float64
for name, value := range requested {
fraction := float64(value) / float64(allocable[name])
for i := range requested {
if allocable[i] == 0 {
continue
}
fraction := float64(requested[i]) / float64(allocable[i])
if fraction > 1 {
fraction = 1
}