Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --concurrent-horizontal-pod-autoscaler-syncs flag to kube-controller-manager #108501

Merged
merged 1 commit into from Oct 17, 2022

Conversation

zroubalik
Copy link
Contributor

@zroubalik zroubalik commented Mar 3, 2022

Signed-off-by: Zbynek Roubalik zroubalik@gmail.com

What type of PR is this?

/kind feature
/kind api-change

What this PR does / why we need it:

While many other controllers like deployment have flag --concurrent-xxx-syncs to set the number of workers, the HPA controller doesn't and just hardcoded with 1 worker. It is very slow to deal with a large number of HPAs in the cluster. This PR exports a flag --concurrent-horizontal-pod-autoscaler-syncs with the default value of 5 for the HPA controller.

Which issue(s) this PR fixes:

Fixes #96242

Special notes for your reviewer:

Does this PR introduce a user-facing change?

kube-controller-manager supports '--concurrent-horizontal-pod-autoscaler-syncs' flag to set the number of horizontal pod autoscaler controller workers.

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. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 3, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @zroubalik. 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.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Mar 3, 2022
@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 3, 2022
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@yusank
Copy link

yusank commented Mar 4, 2022

You should add Mutex Lock for all maps in HorizontalController, otherwise it will be cause of concurrent map writes.

@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 Mar 4, 2022
@zroubalik
Copy link
Contributor Author

You should add Mutex Lock for all maps in HorizontalController, otherwise it will be cause of concurrent map writes.

Good catch, fixed in 95612b5

PTAL

@fedebongio
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Mar 8, 2022
@pigletfly
Copy link
Member

/ok-to-test

@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 Mar 9, 2022
@k8s-ci-robot k8s-ci-robot added area/code-generation sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Mar 10, 2022
Copy link
Contributor

@mwielgus mwielgus left a comment

Choose a reason for hiding this comment

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

/approve

@pbetkier
Copy link
Contributor

@liggitt @deads2k asking for your approves.

@liggitt liggitt self-assigned this Oct 12, 2022
@liggitt liggitt added this to In progress in API Reviews Oct 13, 2022
Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

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

@zroubalik I would like to see that the feature improves the recalculation speed. There is a qps-limit that also can be a bottle-neck when using multiple HPAs.

Could you please provide some benchmarks/measurements that show the improvement? I'm asking that because the change introduces additional complexity to the algorithm and it's debbugability, so a justification that the feature is useful would be great!

Unfortunately I don't have any specific numbers, but as you can see on the linked issues, there are users facing exactly this kind of problem.

given that there are several shared objects in the controller that have to be locked and introduce contention between the workers, the benchmarks to show the actual impact of this still seems like a good idea

I also noted places where the current locking is not safely protecting against races, which also indicates more test coverage is needed

pkg/controller/podautoscaler/horizontal.go Show resolved Hide resolved
pkg/controller/podautoscaler/horizontal.go Show resolved Hide resolved
@liggitt liggitt moved this from In progress to Changes requested in API Reviews Oct 13, 2022
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 14, 2022
@zroubalik
Copy link
Contributor Author

I extended the test a little bit, now it also access scaleUpEvents and scaleDownEvents maps.

I run the test serveral times, it reconciles 5000 HPAs and on my machine:

  • with 1 worker the average test execution is ~26s
  • with 5 workers the average test execution is ~7.5s

PTAL

@pbetkier
Copy link
Contributor

pbetkier commented Oct 14, 2022

I run the test serveral times, it reconciles 5000 HPAs and on my machine:

  • with 1 worker the average test execution is ~26s
  • with 5 workers the average test execution is ~7.5s

Since the test stubs calls to api-server (including metrics-server) it cannot discover bottlenecks like qps-limit or other coming from how the system behaves as a whole.

I think the best way to measure the improvement would be to run a comparison in a large cluster – the promise of this feature is to make HPA reconcile faster in large clusters. Creating a large cluster for tests would be costly though. Perhaps you can emulate the performance problem in a smaller cluster, by simulating a high latency of a custom metrics backend – that's another use case where we expect to see better results after this change (#96242).

You could e.g. configure a http://github.com/Shopify/toxiproxy sitting in front of custom metrics backend, with a latency fault configured.

@liggitt
Copy link
Member

liggitt commented Oct 14, 2022

needs gofmt run and the added unit test is failing:

    horizontal_test.go:4449: 
        	Error Trace:	/home/prow/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/controller/podautoscaler/horizontal_test.go:4449
        	Error:      	Not equal: 
        	            	expected: 5000
        	            	actual  : 1484
        	Test:       	TestMultipleHPAs
        	Messages:   	Expected to process all HPAs

@zroubalik
Copy link
Contributor Author

zroubalik commented Oct 14, 2022

needs gofmt run and the added unit test is failing:

    horizontal_test.go:4449: 
        	Error Trace:	/home/prow/go/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/pkg/controller/podautoscaler/horizontal_test.go:4449
        	Error:      	Not equal: 
        	            	expected: 5000
        	            	actual  : 1484
        	Test:       	TestMultipleHPAs
        	Messages:   	Expected to process all HPAs

Fixed, 5000 HPAs was too optimistic number for this infra, so it has fallen into timeout trap.

…oller-manager

Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
@zroubalik
Copy link
Contributor Author

/retest

@liggitt
Copy link
Member

liggitt commented Oct 17, 2022

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 17, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, mwielgus, pbetkier, zroubalik

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

The pull request process is described here

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 Oct 17, 2022
@k8s-ci-robot k8s-ci-robot merged commit 85643c0 into kubernetes:master Oct 17, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Oct 17, 2022
@liggitt liggitt moved this from Changes requested to API review completed, 1.26 in API Reviews Nov 10, 2022
chenchun pushed a commit to chenchun/kubernetes that referenced this pull request Mar 20, 2024
…quest !873)

1.20:移植1.26支持多个HPAControlller worker
add `--concurrent-horizontal-pod-autoscaler-syncs` flag to kube-controller-manager

为满足作业帮需求,移植PR:kubernetes#108501
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/code-generation cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.26