Skip to content

Improve benchmark performance by using lightweight fake clientsets#9841

Open
Choraden wants to merge 3 commits into
kubernetes:masterfrom
Choraden:ca-bench-impr
Open

Improve benchmark performance by using lightweight fake clientsets#9841
Choraden wants to merge 3 commits into
kubernetes:masterfrom
Choraden:ca-bench-impr

Conversation

@Choraden

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

After profiling the benchmark execution, it was found that the majority of execution time was spent building the cluster state due to slow schema validation in the standard fake clientset.

Introducing and using NewSimpleFakeSet with the lightweight NewSimpleClientset avoids this validation overhead and significantly speeds up the benchmark execution.

Huge thanks to @tetianakh for asking the right questions that lead to this improvement!

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

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


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 19, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If SIG Autoscaling contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 Issues or PRs related to the Cluster Autoscaler component do-not-merge/needs-area Indicates that a PR should not merge because it lacks an area label. labels Jun 19, 2026
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed do-not-merge/needs-area Indicates that a PR should not merge because it lacks an area label. labels Jun 19, 2026
After profiling the benchmark execution, it was found that
the majority of execution time was spent building the cluster
state due to slow schema validation in the standard fake clientset.

Introducing and using NewSimpleFakeSet with the lightweight
NewSimpleClientset avoids this validation overhead and
significantly speeds up the benchmark execution.
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 19, 2026
Increasing the benchmark run count from 6 to 10 in the GitHub
workflow provides more samples for benchstat, resulting in
more reliable and statistically stable performance comparison results.
This adjustment is made possible by the recent benchmark duration improvements.
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Choraden
Once this PR has been reviewed and has the lgtm label, please assign jackfrancis for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

The scale-up benchmark setup is increased from 200 to 1000 nodes,
and the scale-down benchmark setup is increased from 400 to 2000 nodes.
The criteria was stability of the results and similar execution time for
both scenarios.

This larger scale represents a more realistic workload size for
cluster-autoscaler performance testing, made feasible by the recent
optimizations that significantly speed up fake clientset operations.
@Choraden

Copy link
Copy Markdown
Contributor Author

@GaetanoMar96 Please take a look at integration utils changes. Thanks!


options := config.ResolveOptions()
infra := integration.SetupInfrastructure(t)
infra := integration.SetupSimpleInfrastructure(t)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we switching to the simple clientset here? Also, I was wondering if we can get rid of this duplicated pattern of non-simple/simple clientsets and infrastructures in the main test utils.

My suggestion is to create a utils.go under the bench directory that includes these "simple" functions. This would make it easier for people creating benchmarks to know how to correctly write them, as right now it is not obvious to a user which functions to use in which case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are switching it here, cause it does not work with non-simple clientset.
Notice that previously NewFakeSet returned non-simple clientset and simple provreq clientset. To standardize it I introduced a clear distinction. NewFakeSet returns non-simple clients. NewSimpleFakeSet returns simple clients where possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This would make it easier for people creating benchmarks to know how to correctly write them, as right now it is not obvious to a user which functions to use in which case.

This is why benchmark has internal newClusterFakes() function that defaults clientsets.

@@ -200,7 +200,7 @@ func (s scenario) runIteration(b *testing.B, i int, fProf, fTrace *os.File) {

// newClusterFakes initializes a fake cluster with predefined resource limits.
func newClusterFakes() *integration.FakeSet {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the overall benchmark suite currently lacks a README and detailed documentation, and knowing that other people will be working on this in the future, it would be really helpful to enhance it now.

Adding a quick README.md to the cluster-autoscaler/core/bench/ directory explaining how to properly write and run these benchmarks would be highly valuable. This also ties into my previous point: moving the benchmark-specific "simple" setup functions into a dedicated utils.go inside the bench directory, alongside a README, would make the setup much more obvious and maintainable for future contributors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I agree that we could migrate all clientset utils closer to benchmark itself. It also depends on the future of test/integration utils.
Unfortunately, I don't have much time to work on this refactor now, so let's park the idea.
Regarding README.md it is being worked on in separate PR.

@Choraden

Copy link
Copy Markdown
Contributor Author

/retest

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

@Choraden: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-autoscaling-e2e-gci-gce-ca-test 41aa754 link false /test pull-autoscaling-e2e-gci-gce-ca-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cluster-autoscaler Issues or PRs related to the Cluster Autoscaler component cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants