From 077ba4d4c466653954e29c71765cf15e6af8cb30 Mon Sep 17 00:00:00 2001 From: Maciek Pytel Date: Thu, 13 Aug 2020 15:34:14 +0200 Subject: [PATCH] Use FitsAnyNode in binpacking 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. --- .../estimator/binpacking_estimator.go | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cluster-autoscaler/estimator/binpacking_estimator.go b/cluster-autoscaler/estimator/binpacking_estimator.go index 05ec6fde1ef5..45d5f792b9c4 100644 --- a/cluster-autoscaler/estimator/binpacking_estimator.go +++ b/cluster-autoscaler/estimator/binpacking_estimator.go @@ -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) @@ -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) @@ -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)