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

fix(cache): update cache with O(1) data structures #780

Merged
merged 7 commits into from
Mar 4, 2022

Conversation

bbatha
Copy link
Contributor

@bbatha bbatha commented Mar 1, 2022

The prior implementation used arrays to store cached objects. This meant
that updates were O(n). In a controller I developed that managed ~70k PV
and ~70k pvc 99.9% of CPU time was spent in cache updates pegging the
entire process. This new implementation doesn't even have cache updates
show up in the profiles and is using ~25m cpu for the same number of
objects.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 1, 2022
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 1, 2022
@bbatha bbatha force-pushed the fix-cache-performance branch from ed2a8c5 to d97cfc8 Compare March 1, 2022 18:50
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 1, 2022
@bbatha bbatha marked this pull request as draft March 1, 2022 18:57
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2022
expect(cache.get('name1')).to.equal(list[0]);
expect(cache.get('name2')).to.equal(list[1]);
expect(cache.get('name1', 'default')).to.equal(list[0]);
expect(cache.get('name2', 'default')).to.equal(list[1]);
Copy link
Contributor Author

@bbatha bbatha Mar 1, 2022

Choose a reason for hiding this comment

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

I changed the test here to take the default namespace. The old logic didn't make much sense and it seemed like it was supposed to return undefined if the name and namespace did not match. From a consumer perspective I would expect the namespace to only be optional if the resource is global like a namespace or pv. Let me know I should restore the old behavior of finding the first object with a matching name regardless of what namespace its in if no namespace is provided.

Copy link
Contributor

Choose a reason for hiding this comment

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

In the case of this test, the objects are global, they are V1Namespace so I think this test shouldn't change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see this test incorrectly puts namespace in the mocked responses so the namespace objects have namespaces. I'll split this into two tests one for namespace objects and one for unnamespaced objects.

src/cache.ts Show resolved Hide resolved
@bbatha bbatha marked this pull request as ready for review March 1, 2022 20:41
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2022
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 3, 2022
bbatha added 7 commits March 3, 2022 15:24
The prior implementation used arrays to store cached objects. This meant
that updates were O(n). In a controller I developed that managed ~70k PV
and ~70k pvc 99.9% of CPU time was spent in cache updates pegging the
entire process. This new implementation doesn't even have cache updates
show up in the profiles and is using ~25m cpu for the same number of
objects.
@bbatha bbatha force-pushed the fix-cache-performance branch from 15e74b9 to a589f36 Compare March 3, 2022 20:41
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 3, 2022
@bbatha bbatha requested a review from brendandburns March 3, 2022 20:41
@brendandburns
Copy link
Contributor

/lgtm
/approve

Thanks for the PR!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bbatha, brendandburns

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 Mar 4, 2022
@k8s-ci-robot k8s-ci-robot merged commit a5264eb into kubernetes-client:master Mar 4, 2022
@bbatha bbatha deleted the fix-cache-performance branch March 4, 2022 19:51
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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