performance(detector): reduce lock contention in waitingObkects matching logic#7175
performance(detector): reduce lock contention in waitingObkects matching logic#7175zhzhuang-zju wants to merge 1 commit intokarmada-io:masterfrom
Conversation
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello @zhzhuang-zju, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a performance optimization within the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the waitingObjects data structure to use a sync.Map with more granular locking, aiming to reduce lock contention. However, the current implementation introduces a cross-namespace resource interference vulnerability and a Denial of Service risk. Specifically, the GetMatching function incorrectly handles empty namespaces in resource selectors, leading to unintended matching across namespaces for namespaced policies. Additionally, holding a read lock during potentially slow API server lookups can block other controller operations, contributing to the Denial of Service risk.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7175 +/- ##
==========================================
- Coverage 42.08% 42.05% -0.04%
==========================================
Files 871 871
Lines 53301 53341 +40
==========================================
- Hits 22432 22431 -1
- Misses 29184 29224 +40
- Partials 1685 1686 +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:
|
|
/retitle performance(detector): reduce lock contention in waitingObkects matching logic |
What type of PR is this?
/kind feature
What this PR does / why we need it:
waitingObjectsis designed to track resource templates that haven't been propagated due to a lack of a matching (Cluster)PropagationPolicy. The current implementation has the following issues:Coarse-grained Locking: Any read/write operation locks the entire waitingObjects, leading to severe lock contention in large-scale clusters.Inefficient Matching: Each policy match requires a full traversal of all waiting objects, resulting inThis PR introduces the following optimizations:
Which issue(s) this PR fixes:
Part of #7139
Special notes for your reviewer:
Test Environment:

The environment contains approximately 60k-70k workloads distributed across different namespaces, with 7k-8k per single namespace. Workloads are dispatched to member clusters via policies.
In addition, there are thousands of dependent resources such as PVCs and 20k-30k ConfigMaps. These do not have separately bound policies but are dispatched to member clusters along with the workloads through the dependent propagation feature.
Now, restart karmada-controller-manager.
For the analysis of this figure, you can refer to: #7139 (comment)
After optimization:

As seen from the images:
Does this PR introduce a user-facing change?: