Skip to content

Optimize RS Controller Performance: Reduce Work Duration Time & Minimize Cache Locking #130961

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

hakuna-matatah
Copy link
Contributor

@hakuna-matatah hakuna-matatah commented Mar 21, 2025

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This PR introduces a Daemonset indexer for the PodInformer to efficiently query Pods belonging to Daemonsets or Orphans from the InformerCache, avoiding a full namespace scan.

This improves performance and correctness at scale by minimizing the time a read lock is held on the cache, reducing blockage of CacheController delta processing. It also helps lower workqueue processing time per object/key.

I did some benchmarking against Indexing (vs) purely listing the pods from Store/Cache

For 10k pods in store, using Index it took ~30 µs (vs) ~320 µs

For 500k pods in store, using Index it took ~35 µs (vs) 18.080762ms

We can tell that, listing from store using Index is 500X times better at higher scale.

Following are the results :

=== RUN   TestGetPodsForDaemonSetUsesIndexer
    daemon_controller_test.go:922: ByIndex() fetched 100 pods in 30.252µs
    daemon_controller_test.go:930: List() fetched 10000 pods in 320.047µs
=== RUN   TestGetPodsForDaemonSetUsesIndexer
    daemon_controller_test.go:922: ByIndex() fetched 100 pods in 37.842µs
    daemon_controller_test.go:930: List() fetched 500000 pods in 18.080762ms

Optimizing this list call will provide the following benefits:

  • Reduce Read Lock Duration on the InformerCache, allowing writes to proceed faster and reducing chances of cache staleness at scale.
  • Lower Work Queue Processing Time, enabling faster convergence to the desired state.
  • Decreased Queue Wait Time,, ensuring items are dispatched and processed more efficiently

Made similar improvement for DS controller and Statefulset controller

Which issue(s) this PR fixes:

Fixes # #130767

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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. 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-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/apps Categorizes an issue or PR as relevant to SIG Apps. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 21, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG Apps Mar 21, 2025
@hakuna-matatah
Copy link
Contributor Author

/assign @soltysh

@hakuna-matatah
Copy link
Contributor Author

cc: @dims

@hakuna-matatah
Copy link
Contributor Author

/assign @wojtek-t

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 24, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2025
@dims
Copy link
Member

dims commented Apr 30, 2025

@hakuna-matatah the linter CI job is a easy fix, do you want to do that then we can ping folks for review?

@atiratree
Copy link
Member

/triage accepted
/priority important-soon

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 2, 2025
@soltysh
Copy link
Contributor

soltysh commented May 7, 2025

/assign @soltysh

Sorry, this slipped through the cracks. @hakuna-matatah can you rebase the PR, fix that linter error (adding //nolint:errcheck is ok for that one the linter is failing on, and then ping me on slack for a re-review on this one?

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 12, 2025
@hakuna-matatah
Copy link
Contributor Author

@soltysh Sorry for the delayed response, I have been on vacation. Please check now if you get a chance.

@hakuna-matatah
Copy link
Contributor Author

/retest

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/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 May 13, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: a9606cc0a2acc8b2239c5fd9255724556c746b4e

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hakuna-matatah, soltysh

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 May 13, 2025
@k8s-ci-robot k8s-ci-robot merged commit 1325262 into kubernetes:master May 13, 2025
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.34 milestone May 13, 2025
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in SIG Apps May 13, 2025
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. 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. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants