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

✨ SSA: Implement request caching #8207

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

sbueringer
Copy link
Member

@sbueringer sbueringer commented Mar 1, 2023

What this PR does / why we need it:
In recent weeks we added in-place propagation across a few controllers and we introduced an additional SSA dryrun in our Cluster topology controller. Basically on every reconcile we run SSA against the apiserver.

Now it's time to optimize the amounts of SSA calls to avoid overloading the apiserver.

This PR implements caching for SSA requests. The high-level idea is that once we know for a given original and modified object that the request doesn't lead to any changes, we cache this information for 10 minutes.

SSA will only be executed again once either original or modified objects change or the 10 minutes are over.

Some data:
Screenshot 2023-03-01 at 06 12 29

The first two are ~ quickstart cluster creations with ClusterClass & caching => ~ 148 Patch calls
The last one is the same without caching => ~ 310 Patch calls until the cluster exists and then just continuous calls.

This PR currently contains caching for:

  • Cluster topology SSA
  • MachineDeployment => MachineSet
  • MachineSet => Machine, InfraMachine, BootstrapConfig
  • KCP => Machine, InfraMachine, BootstrapConfig
  • Machine => Node

The difference should be even bigger once we implemented KCP reconciliation with SSA.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #8146

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 1, 2023
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 1, 2023
@sbueringer
Copy link
Member Author

/test pull-cluster-api-e2e-full-main

@fabriziopandini
Copy link
Member

kudos for collecting those data!
this proof our assumptions are true, and so we need this work to merge as soon as possible

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 1, 2023
@sbueringer sbueringer changed the title [WIP] ✨ SSA: Implement request caching ✨ SSA: Implement request caching Mar 1, 2023
@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, 2023
@sbueringer
Copy link
Member Author

/retest

@sbueringer
Copy link
Member Author

Refactored based on suggestions and discussions from/with Fabrizio. Also adde unit tests and godoc. Should be ~ ready.

@sbueringer
Copy link
Member Author

@fabriziopandini @ykakarap PTAL :)

@sbueringer
Copy link
Member Author

/hold

Let's merge #8213 before this PR. I want to have the metrics on main before this PR

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 2, 2023
@sbueringer
Copy link
Member Author

/test pull-cluster-api-e2e-full-main

@sbueringer
Copy link
Member Author

/test pull-cluster-api-e2e-full-main

@sbueringer
Copy link
Member Author

/retest

Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

The overall implementation looks great!
Thanks for doing this 🙂.

Just small nits.

internal/util/ssa/cache.go Outdated Show resolved Hide resolved
internal/util/ssa/cache.go Outdated Show resolved Hide resolved
internal/util/ssa/cache.go Show resolved Hide resolved
internal/util/ssa/patch.go Outdated Show resolved Hide resolved
internal/util/ssa/patch_test.go Outdated Show resolved Hide resolved
internal/util/ssa/patch_test.go Outdated Show resolved Hide resolved
internal/util/ssa/patch_test.go Outdated Show resolved Hide resolved
@fabriziopandini
Copy link
Member

lgtm from my side, ping me when the last round of nits is fixed

@sbueringer
Copy link
Member Author

sbueringer commented Mar 2, 2023

/test pull-cluster-api-e2e-full-main

/hold

Want to have full e2e test results before merging

@fabriziopandini
Copy link
Member

/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 Mar 2, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 0020cbb8f4de2d8a3cabfd8d4e10d14faf8a2512

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

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 2, 2023
@sbueringer
Copy link
Member Author

I'll merge once ci is green and we're done with the new v1.4 beta release

@sbueringer
Copy link
Member Author

I'll wait a bit longer. I would like to have at least 1-2 green runs of the periodics with metrics + propagation fully implemented so I can compare before/after this optimization

@ykakarap
Copy link
Contributor

ykakarap commented Mar 2, 2023

/lgtm

@sbueringer
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 2, 2023
@k8s-ci-robot k8s-ci-robot merged commit c680942 into kubernetes-sigs:main Mar 2, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.4 milestone Mar 2, 2023
@sbueringer sbueringer deleted the pr-ssa-caching branch March 2, 2023 20:44
@sbueringer
Copy link
Member Author

Took a look at the data before/after this PR merged:

Cluster topology controller:

  • 10.96.0.1:443 cluster.x-k8s.io clusters
    • normal: 10
    • dryrun: 984 => 304
  • 10.96.0.1:443 cluster.x-k8s.io machinedeployments
    • normal: 18 => 19
    • dryrun: 958 => 178
  • 10.96.0.1:443 cluster.x-k8s.io machinehealthchecks:
    • normal: 18
    • dryrun: 1630 => 260
  • 10.96.0.1:443 controlplane.cluster.x-k8s.io kubeadmcontrolplanes:
    • normal: 25
    • dryrun: 964 => 588
  • 10.96.0.1:443 infrastructure.cluster.x-k8s.io dockerclusters
    • normal: 11 => 10
    • dryrun: 964 => 62
  • 10.96.0.1:443 bootstrap.cluster.x-k8s.io kubeadmconfigtemplates
    • normal: 15
    • dryrun: 958 => 44
  • 10.96.0.1:443 infrastructure.cluster.x-k8s.io dockermachinetemplates
    • normal: 37
    • dryrun: 1922 => 110

MD controller:

  • 10.96.0.1:443 cluster.x-k8s.io machinesets: 892 => 753
    => TODO: the reduction doesn't look good enough

MS controller:

  • 10.96.0.1:443 cluster.x-k8s.io machines: 1650 => 570
  • 10.96.0.1:443 infrastructure.cluster.x-k8s.io dockermachines: 1613 => 205
  • 10.96.0.1:443 bootstrap.cluster.x-k8s.io kubeadmconfigs: 1613 => 151

Machine controller: (various workload clusters)

  • 172.18.0.10: v1/nodes 526 => 18
  • 172.18.0.3: v1/nodes 977 => 147
  • 172.18.0.4: v1/nodes 2075 => 83
  • 172.18.0.5: v1/nodes 729 => 73
  • 172.18.0.6: v1/nodes 353 => 128
  • 172.18.0.7: v1/nodes 601 => 43
  • 172.18.0.8: v1/nodes 135 => 41

=> Before: 19663 => After: 3892

KCP controller:

  • 10.96.0.1:443 cluster.x-k8s.io machines 4404 => 4131
  • 10.96.0.1:443 bootstrap.cluster.x-k8s.io kubeadmconfigs: 4355 => 4089
  • 10.96.0.1:443 infrastructure.cluster.x-k8s.io dockermachines 4355 => 4089
    => TODO: the reduction doesn't look good enough

tl;dr 5x reduction of calls for everything except KCP and MD controller. I'll take a look at those, maybe the caching doesn't work there for some reason

@sbueringer
Copy link
Member Author

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClusterClass: cache SSA dry-run requests
5 participants