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

Optimize deprioritized policy preemption logic #4555

Merged

Conversation

whitewindmills
Copy link
Member

@whitewindmills whitewindmills commented Jan 16, 2024

What type of PR is this?
/kind feature
/kind cleanup

What this PR does / why we need it:
Using the natural ordering properties of red-black trees to sort the listed policies to ensure the higher priority (Cluster)PropagationPolicy being processed first to avoid possible multiple preemption.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 16, 2024
@karmada-bot karmada-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 16, 2024
@whitewindmills
Copy link
Member Author

/cc @RainbowMango @chaosi-zju

@codecov-commenter
Copy link

codecov-commenter commented Jan 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 44 lines in your changes are missing coverage. Please review.

Project coverage is 51.40%. Comparing base (413a15a) to head (e88797b).
Report is 76 commits behind head on master.

Files Patch % Lines
pkg/detector/preemption.go 0.00% 44 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4555      +/-   ##
==========================================
- Coverage   51.86%   51.40%   -0.47%     
==========================================
  Files         243      250       +7     
  Lines       24183    24979     +796     
==========================================
+ Hits        12543    12840     +297     
- Misses      10959    11433     +474     
- Partials      681      706      +25     
Flag Coverage Δ
unittests 51.40% <0.00%> (-0.47%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@whitewindmills
Copy link
Member Author

ping @RainbowMango @chaosi-zju
Kindly help to take a look, thanks.

@chaosi-zju
Copy link
Member

the code in this PR looks good, thank you for your effort!

@RainbowMango
Copy link
Member

Using the natural ordering properties of red-black trees to sort the listed policies to ensure the higher priority (Cluster)PropagationPolicy being processed first to avoid possible multiple preemption.

Seems this PR trying to fix a bug?

@whitewindmills
Copy link
Member Author

Seems this PR trying to fix a bug?

More like optimization cause multiple preemptions do not affect its functionality.

@whitewindmills whitewindmills force-pushed the deprioritized-preemption branch from 845da7d to 9dc6be7 Compare January 22, 2024 03:54
@whitewindmills
Copy link
Member Author

@chaosi-zju @RainbowMango
PTAL~

Copy link
Member

@chaunceyjiang chaunceyjiang left a comment

Choose a reason for hiding this comment

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

Thanks~

This is a great optimization.

LGTM.

@whitewindmills
Copy link
Member Author

ping @RainbowMango

@RainbowMango
Copy link
Member

/assign

pkg/detector/preemption.go Outdated Show resolved Hide resolved
pkg/detector/preemption.go Show resolved Hide resolved
pkg/detector/preemption.go Outdated Show resolved Hide resolved
@RainbowMango
Copy link
Member

By the way, have you ever considered the PriorityQueue which looks like more simple than the tree.

@whitewindmills
Copy link
Member Author

By the way, have you ever considered the PriorityQueue which looks like more simple than the tree.

Nice reminder.

@whitewindmills whitewindmills force-pushed the deprioritized-preemption branch from 9dc6be7 to efd56ec Compare February 28, 2024 10:00
@karmada-bot karmada-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 28, 2024
@whitewindmills
Copy link
Member Author

Their performance is almost the same(both O(logN), but using the priority queue code is more concise.
@RainbowMango PTAL

@RainbowMango
Copy link
Member

Seems the related testing is failing:

• [FAILED] [425.271 seconds]
[Preemption] propagation policy preemption testing when [ClusterPropagationPolicy Preemption] ClusterPropagationPolicy preempts another ClusterPropagationPolicy High-priority ClusterPropagationPolicy reduces priority to be preempted by low-priority ClusterPropagationPolicy [It] Propagate the deployment with the high-priority ClusterPropagationPolicy and then reduce it's priority to be preempted by the low-priority ClusterPropagationPolicy

https://github.com/karmada-io/karmada/actions/runs/8078521320/job/22071318982?pr=4555

@whitewindmills whitewindmills force-pushed the deprioritized-preemption branch from efd56ec to acad217 Compare February 29, 2024 02:48
@whitewindmills whitewindmills force-pushed the deprioritized-preemption branch from acad217 to 7bda80d Compare February 29, 2024 06:40
Use the priorityequeue to sort the listed policies to avoid multiple preemption.

Signed-off-by: whitewindmills <[email protected]>
@whitewindmills whitewindmills force-pushed the deprioritized-preemption branch from 7bda80d to e88797b Compare February 29, 2024 07:55
@whitewindmills
Copy link
Member Author

@RainbowMango Ready to review again.

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
Thanks.

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 1, 2024
@karmada-bot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 1, 2024
@karmada-bot karmada-bot merged commit 2cfa7e6 into karmada-io:master Mar 1, 2024
12 checks passed
@whitewindmills whitewindmills deleted the deprioritized-preemption branch April 19, 2024 03:18
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants