mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-19 16:05:11 +00:00
Improve performance of NodeResourcesFit scoring
Signed-off-by: tangwz <tangwz.com@gmail.com>
This commit is contained in:
@@ -24,9 +24,6 @@ import (
|
||||
schedutil "k8s.io/kubernetes/pkg/scheduler/util"
|
||||
)
|
||||
|
||||
// resourceToWeightMap contains resource name and weight.
|
||||
type resourceToWeightMap map[v1.ResourceName]int64
|
||||
|
||||
// scorer is decorator for resourceAllocationScorer
|
||||
type scorer func(args *config.NodeResourcesFitArgs) *resourceAllocationScorer
|
||||
|
||||
@@ -35,14 +32,11 @@ type resourceAllocationScorer struct {
|
||||
Name string
|
||||
// used to decide whether to use Requested or NonZeroRequested for
|
||||
// cpu and memory.
|
||||
useRequested bool
|
||||
scorer func(requested, allocable resourceToValueMap) int64
|
||||
resourceToWeightMap resourceToWeightMap
|
||||
useRequested bool
|
||||
scorer func(requested, allocable []int64) int64
|
||||
resources []config.ResourceSpec
|
||||
}
|
||||
|
||||
// resourceToValueMap is keyed with resource name and valued with quantity.
|
||||
type resourceToValueMap map[v1.ResourceName]int64
|
||||
|
||||
// score will use `scorer` function to calculate the score.
|
||||
func (r *resourceAllocationScorer) score(
|
||||
pod *v1.Pod,
|
||||
@@ -51,18 +45,21 @@ func (r *resourceAllocationScorer) score(
|
||||
if node == nil {
|
||||
return 0, framework.NewStatus(framework.Error, "node not found")
|
||||
}
|
||||
if len(r.resourceToWeightMap) == 0 {
|
||||
// resources not set, nothing scheduled,
|
||||
if len(r.resources) == 0 {
|
||||
return 0, framework.NewStatus(framework.Error, "resources not found")
|
||||
}
|
||||
|
||||
requested := make(resourceToValueMap)
|
||||
allocatable := make(resourceToValueMap)
|
||||
for resource := range r.resourceToWeightMap {
|
||||
alloc, req := r.calculateResourceAllocatableRequest(nodeInfo, pod, resource)
|
||||
if alloc != 0 {
|
||||
// Only fill the extended resource entry when it's non-zero.
|
||||
allocatable[resource], requested[resource] = alloc, req
|
||||
requested := make([]int64, len(r.resources))
|
||||
allocatable := make([]int64, len(r.resources))
|
||||
for i := range r.resources {
|
||||
alloc, req := r.calculateResourceAllocatableRequest(nodeInfo, pod, v1.ResourceName(r.resources[i].Name))
|
||||
// Only fill the extended resource entry when it's non-zero.
|
||||
if alloc == 0 {
|
||||
continue
|
||||
}
|
||||
allocatable[i] = alloc
|
||||
requested[i] = req
|
||||
}
|
||||
|
||||
score := r.scorer(requested, allocatable)
|
||||
@@ -137,12 +134,3 @@ func (r *resourceAllocationScorer) calculatePodResourceRequest(pod *v1.Pod, reso
|
||||
|
||||
return podRequest
|
||||
}
|
||||
|
||||
// resourcesToWeightMap make weightmap from resources spec
|
||||
func resourcesToWeightMap(resources []config.ResourceSpec) resourceToWeightMap {
|
||||
resourceToWeightMap := make(resourceToWeightMap)
|
||||
for _, resource := range resources {
|
||||
resourceToWeightMap[v1.ResourceName(resource.Name)] = resource.Weight
|
||||
}
|
||||
return resourceToWeightMap
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user