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

Use indexer when listing cached types by hash #326

Merged
merged 2 commits into from
Dec 22, 2023

Conversation

aruiz14
Copy link
Contributor

@aruiz14 aruiz14 commented Oct 13, 2023

Relates to rancher/fleet#1842

Extending WithCacheType option, those types will be indexed by their hash label (objectset.rio.cattle.io/hash), which every object produced or modified by Apply has. This is a direct replacement for using List with an exact label selector, which is certainly more expensive.
The ultimate goal of this change is reducing CPU usage, which has been successfully observed by testing this change in a custom Fleet build (along with rancher/fleet#1857), where in some cases produced around 40%-50% CPU drop (see SURE-6990).

@aruiz14 aruiz14 changed the title Add indexer by hash for cached types Use indexer when listing cached types by hash Oct 13, 2023
@aruiz14 aruiz14 marked this pull request as ready for review November 22, 2023 14:43
pkg/apply/desiredset.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rmweir rmweir left a comment

Choose a reason for hiding this comment

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

Small nit then LGTM.

pkg/apply/desiredset.go Outdated Show resolved Hide resolved
@aruiz14 aruiz14 requested a review from rmweir December 13, 2023 10:43
Copy link
Contributor

@KevinJoiner KevinJoiner left a comment

Choose a reason for hiding this comment

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

Two minor nits, but they don't change the validity of the changes here.

pkg/apply/desiredset_process.go Outdated Show resolved Hide resolved
pkg/apply/desiredset_process_test.go Show resolved Hide resolved
@@ -109,3 +113,157 @@ func Test_multiNamespaceList(t *testing.T) {
})
}
}

func Test_canIndexByHash(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is nothing to change here; it's just a suggestion for future tests. We would get a lot of mileage by having one test function for the entire list(...) function since we can better verify the desired interaction with the current behavior.

@aruiz14 aruiz14 force-pushed the hash-indexer branch 2 times, most recently from d137c74 to c3044b9 Compare December 14, 2023 17:17
@aruiz14
Copy link
Contributor Author

aruiz14 commented Dec 14, 2023

@KevinJoiner I had to upgrade the golangci-lint GH action because it was failing for every commit (I even tested re-running it for an old one that already succeeded in the past).
Please let me know if I should revert it and maybe create a separate PR.

Copy link
Contributor

@KevinJoiner KevinJoiner left a comment

Choose a reason for hiding this comment

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

You can either squash all the commits other than the lint update and force push or we can just squash everything when we merge.

@aruiz14
Copy link
Contributor Author

aruiz14 commented Dec 15, 2023

You can either squash all the commits other than the lint update and force push or we can just squash everything when we merge.

Done! Thanks for your review!

Copy link
Contributor

@rmweir rmweir left a comment

Choose a reason for hiding this comment

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

LGTM

@moio
Copy link
Contributor

moio commented Dec 18, 2023

@KevinJoiner I see I cannot merge this, can you help?

@cwayne18 cwayne18 merged commit 3040716 into rancher:master Dec 22, 2023
2 checks passed
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 3, 2024
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 5, 2024
* Add indexer by hash for cached types

* Upgrade golangci-lint GitHub action, since it always fails now
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 9, 2024
aruiz14 added a commit to aruiz14/wrangler that referenced this pull request Jan 10, 2024
* Add indexer by hash for cached types

* Upgrade golangci-lint GitHub action, since it always fails now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants