Skip to content

Conversation

@yonizxz
Copy link
Contributor

@yonizxz yonizxz commented Jan 29, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

An optimization of the binpacking algorithm.
The standard binpacking algorithm operates by simulating the scheduling of all pods.
If pods cannot be scheduled on existing nodes in the simulation, new nodes are added to the simulation.
The Fastpath logic estimates the required number of nodes using simple arithmetic, avoiding the full simulation. It works by:

  • Simulating the scheduling of pods on a single added node.
  • Calculating the estimated nodes by dividing the number of remaining unscheduled pods by the number of pods it was able to fit on that single node
    EstimatedNodes = ceil(TotalPods / PodsFittingOnASingleNode)

Current BenchmarkBinpackingEstimate results:

=== RUN   BenchmarkBinpackingEstimate
BenchmarkBinpackingEstimate
BenchmarkBinpackingEstimate-24                 1        3756356278 ns/op        2898666960 B/op  4245672 allocs/op
PASS
ok      k8s.io/autoscaler/cluster-autoscaler/estimator  3.869s

BenchmarkBinpackingEstimate with fastpath enabled:

=== RUN   BenchmarkBinpackingEstimate
BenchmarkBinpackingEstimate
BenchmarkBinpackingEstimate-24                25          41417483 ns/op        25758270 B/op     191593 allocs/op
PASS
ok      k8s.io/autoscaler/cluster-autoscaler/estimator  1.202s

Which issue(s) this PR fixes:

Special notes for your reviewer:

Additional explanation:

Since the algorithm only adds 1 node to the snapshot, subsequent iterations will not take the rest of the upcoming nodes into account during tryToScheduleOnExistingNodes, therefore it is used only in the final iteration.
In order to maximize gains from the optimization, a heuristic determines the pod equivalence group that will benefit the most from the fastpath algorithm and preemptively places it at the end of the list.

Does this PR introduce a user-facing change?

Add fastpath binpacking optimization to scale-ups

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Jan 29, 2026
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 29, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @yonizxz!

It looks like this is your first PR to kubernetes/autoscaler 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/autoscaler has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 29, 2026
@k8s-ci-robot
Copy link
Contributor

Hi @yonizxz. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added area/cluster-autoscaler size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/needs-area cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 29, 2026
@yonizxz yonizxz force-pushed the fastpath-binpacking branch 2 times, most recently from 8569f24 to d6c0d7a Compare February 2, 2026 10:49

// Fastpath assumes that once a pod failed to schedule on a node, it will never be possible to schedule any more pods on this node.
// This assumption is not correct in cases of topology spread constraints.
// Fastpath also assumes that if it was able to schedule pods on a new node, it will be able to then schedule an equal amount of pods on an additional identical new node,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is true. Why would zonal/regional anti affinity affect # of pods that can schedule on subsequent nodes?

Copy link
Contributor Author

@yonizxz yonizxz Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to - https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#an-example-of-a-pod-that-uses-pod-affinity

With zonal/regional pod anti affinity, a pod can schedule on a node only if it is in a zone/region that doesn't contain another pod with the same value.

So fastpath will create a new node and will be able to schedule the first pod, and then won't be able to schedule the second one (there's already a pod in the same zone/region, since it's on the same node), and will then assume it can schedule the remaining x pods by creating x more nodes. which is not true, because the node group is bound to a location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right, we'd have to try a second node to check for this. Or just consider anti-affinity matching the pods being considered - this is a bit similar to the discussion in the other thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I suppose if the anti affinity for a different workload, we could theoretically fastpath if there isn't a matching pod in the same location as the node group. But it would be more complicated to adjust for that and I'm not too sure about the gains (how common is it and if these type of workloads are usually big enough to benefit from fastpath). It's simpler to just not support zonal/regional anti affinity altogether, at least for now. If it becomes an important use case we can revisit this later.

@yonizxz yonizxz force-pushed the fastpath-binpacking branch from d6c0d7a to ad35b37 Compare February 4, 2026 13:27
@yonizxz yonizxz force-pushed the fastpath-binpacking branch from ad35b37 to 07f2cb9 Compare February 4, 2026 13:52
@yonizxz yonizxz requested a review from x13n February 5, 2026 12:47
@x13n
Copy link
Member

x13n commented Feb 11, 2026

/ok-to-test
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 11, 2026
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 11, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: x13n, yonizxz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 11, 2026
@k8s-ci-robot k8s-ci-robot merged commit ed56951 into kubernetes:master Feb 11, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants