-
Notifications
You must be signed in to change notification settings - Fork 981
disable deepcopy for list action #5813
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
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #5813 +/- ##
==========================================
+ Coverage 48.14% 48.15% +0.01%
==========================================
Files 677 677
Lines 56048 56068 +20
==========================================
+ Hits 26982 26999 +17
- Misses 27296 27298 +2
- Partials 1770 1771 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
76c7e1c
to
5784ba3
Compare
Regarding this performance optimization, which clearly introduces side effects, I have two suggestions:
|
Through golang pprof analysis, it is found that during the restart period, deep copy will have obvious CPU time loss. After removing it, this part of the loss disappeared. |
This part is what I mean by e2e performance comparison, I'm not saying e2e tests. |
/retest |
5784ba3
to
4a0fb1b
Compare
pls take a look at the e2e performance comparison @zach593 |
Regarding this pprof result, what was the resource level at that time? When the controller is cold started, without or with this commit, how long does it take to clear the queue? How long does a single reconciliation take? Reducing the time taken for an operation by an order of magnitude is great, but I think it would be more helpful to see how much of an overall improvement the change made, especially for an optimization that has potential side effects. |
There is an env |
I will test in a real test environment and give optimization data |
|
karmada/vendor/sigs.k8s.io/controller-runtime/pkg/cache/internal/informers.go Lines 59 to 61 in 0713e4b
The answer is yes, it also applies to controller-runtime, because controller-runtime also uses client-go informer. |
A new concern just popped into my mind: does disabling deepCopy consistently lead to data being in a state of race conditions? |
I don't understand what this sentence means, can you give me an example? |
4a0fb1b
to
a39f21b
Compare
/retest |
I'm wondering if there will be a data race between the reading thread and the informer writing thread. This is something I suddenly realized, and I didn't think about it very seriously. Since I raised this question, I did some research and the result is it should not cause a data race. karmada/vendor/k8s.io/client-go/tools/cache/controller.go Lines 548 to 557 in 9ea0382
From the code above, you can see that when writing to the cache, the entire variable is replaced with the new object from the In other words, if the reading thread modifies the held object in the |
list action disabling deepCopy, must make sure the list item will not be updated, or make a deepcopy of it before updating it. |
a39f21b
to
682d668
Compare
707cb18
to
d62d6df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disable deepcopy indeed can improve performance, but should be used very cautiously.
/assign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me.
But I think we should rename variable name or add more comments to notice the object can not be mutated.
@@ -190,7 +191,7 @@ func (c *ResourceBindingController) newOverridePolicyFunc() handler.MapFunc { | |||
} | |||
|
|||
bindingList := &workv1alpha2.ResourceBindingList{} | |||
if err := c.Client.List(ctx, bindingList); err != nil { | |||
if err := c.Client.List(ctx, bindingList, &client.ListOptions{UnsafeDisableDeepCopy: ptr.To(true)}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to add a namespace
filter? Like:
bindingList := &workv1alpha2.ResourceBindingList{}
- if err := c.Client.List(ctx, bindingList); err != nil {
+ if err := c.Client.List(ctx, bindingList, &client.ListOptions{UnsafeDisableDeepCopy: ptr.To(true), Namespace: namespace}); err != nil {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bindingList
--> readonlyBindingList
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to add a namespace filter
Yes
Controller-runtime has a detailed description of karmada/vendor/sigs.k8s.io/controller-runtime/pkg/client/options.go Lines 495 to 499 in 65e7f74
|
d62d6df
to
3ab9889
Compare
Signed-off-by: chang.qiangqiang <[email protected]>
3ab9889
to
d58cbe1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
When the node CPU usage rate is almost over 90%, it seems that deepcopy cost the most time:
After turning off list deepcopy, the list time is reduced to 0.1s or even lower.
Which issue(s) this PR fixes:
part of #5790
Special notes for your reviewer:
Does this PR introduce a user-facing change?: