Skip to content

Commit

Permalink
Use FitsAnyNode in binpacking
Browse files Browse the repository at this point in the history
This means that PreFilters are run once per pod in binpacking
instead of #pods*#nodes times. This makes a huge performance
difference in very large clusters.
  • Loading branch information
MaciekPytel committed Aug 13, 2020
1 parent 7c5524c commit 9a5f38f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cluster-autoscaler/estimator/binpacking_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (estimator *BinpackingNodeEstimator) Estimate(
podInfos := calculatePodScore(pods, nodeTemplate)
sort.Slice(podInfos, func(i, j int) bool { return podInfos[i].score > podInfos[j].score })

newNodeNames := make([]string, 0)
newNodeNames := make(map[string]bool)

if err := estimator.clusterSnapshot.Fork(); err != nil {
klog.Errorf("Error while calling ClusterSnapshot.Fork; %v", err)
Expand All @@ -80,16 +80,18 @@ func (estimator *BinpackingNodeEstimator) Estimate(

for _, podInfo := range podInfos {
found := false
for _, nodeName := range newNodeNames {
if err := estimator.predicateChecker.CheckPredicates(estimator.clusterSnapshot, podInfo.pod, nodeName); err == nil {
found = true
if err := estimator.clusterSnapshot.AddPod(podInfo.pod, nodeName); err != nil {
klog.Errorf("Error adding pod %v.%v to node %v in ClusterSnapshot; %v", podInfo.pod.Namespace, podInfo.pod.Name, nodeName, err)
return 0
}
break

nodeName, err := estimator.predicateChecker.FitsAnyNodeMatching(estimator.clusterSnapshot, podInfo.pod, func(nodeInfo *schedulerframework.NodeInfo) bool {
return newNodeNames[nodeInfo.Node().Name]
})
if err == nil {
found = true
if err := estimator.clusterSnapshot.AddPod(podInfo.pod, nodeName); err != nil {
klog.Errorf("Error adding pod %v.%v to node %v in ClusterSnapshot; %v", podInfo.pod.Namespace, podInfo.pod.Name, nodeName, err)
return 0
}
}

if !found {
// Add new node
newNodeName, err := estimator.addNewNodeToSnapshot(nodeTemplate, newNodeNameTimestamp, newNodeNameIndex)
Expand All @@ -103,7 +105,7 @@ func (estimator *BinpackingNodeEstimator) Estimate(
klog.Errorf("Error adding pod %v.%v to node %v in ClusterSnapshot; %v", podInfo.pod.Namespace, podInfo.pod.Name, newNodeName, err)
return 0
}
newNodeNames = append(newNodeNames, newNodeName)
newNodeNames[newNodeName] = true
}
}
return len(newNodeNames)
Expand Down

0 comments on commit 9a5f38f

Please sign in to comment.