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

[perf] reduce sts updates during sts reconcilation by using equality check #1197

Closed
wants to merge 1 commit into from

Conversation

nammn
Copy link
Collaborator

@nammn nammn commented Jan 19, 2023

All Submissions:

  • Have you opened an Issue before filing this PR?
  • Have you signed our CLA?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Put closes #XXXX in your comment to auto-close the issue that your PR fixes (if such).

Context

During our replicaset deployment we do the 2 following things in that order:

  • deploy the automation config for our agent [1]
  • deploy the sts for our agent [2]

Then we wait and check at each reconciliation whether either of above steps are done.
At each reconciliation of [2] we wait and create an internal view how a sts has to look like. There is a possibility that the sts has changed during last reconcile. Because of this we send an update request to our api server to make sure our internal view is applied.

This patch makes sure we only send updates if the internal view differs from the current sts.

Note: Depending on how many member [2] has and how long the reconcile takes we can do a lot of reconciles and therefore a lot of update requests.

if err != nil {
if apiErrors.IsNotFound(err) {
return appsv1.StatefulSet{}, getUpdateCreator.CreateStatefulSet(sts)
}
return appsv1.StatefulSet{}, err
}
if equality.Semantic.DeepEqual(currSts, sts) {
Copy link
Collaborator Author

@nammn nammn Jan 19, 2023

Choose a reason for hiding this comment

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

During my local test runs this works fine. This method is preferred since it focuses on semantic equality instead of memory equality.
It might have been enough to check spec and some ownerRefs, but I wanted to be on the safer side.

Alternative:

  • create hash of current sts
  • save hash as annotation on sts
  • check hash of annotation
    -> safer but takes more implementation for something that might not be worth the effort

Copy link
Contributor

Choose a reason for hiding this comment

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

This method is preferred since it focuses on semantic equality instead of memory equality.

I am not sure if I understand the difference here. Would you happen to have an example?

Copy link
Collaborator Author

@nammn nammn Jan 24, 2023

Choose a reason for hiding this comment

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

Sure.

for example, it matches an empty slice with a nil slice and the same for a map.

In our code where we generate an internal view of a statefulset we create empty maps and slices while the api server returns them as nil (or the other way around). With above function equality is true due to semantic equality.

@nammn nammn marked this pull request as ready for review January 19, 2023 16:42
@nammn nammn marked this pull request as draft January 24, 2023 10:40
@github-actions
Copy link
Contributor

This PR is being marked stale because it has been open for 60 days with no activity. Please update the PR or ask for a fresh review.

@github-actions github-actions bot added the stale label Mar 27, 2023
@slaskawi
Copy link
Contributor

Closing as conflicted WIP work. Please reopen if needed.

@slaskawi slaskawi closed this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants