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

Change score logic from serial to parallel #3090

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Poor12
Copy link
Member

@Poor12 Poor12 commented Feb 1, 2023

Signed-off-by: Poor12 [email protected]

What type of PR is this?
/kind cleanup

What this PR does / why we need it:

  1. Incorrect uasge of variables:
    pluginToClusterScores := make(framework.PluginToClusterScores, len(frw.filterPlugins)) => pluginToClusterScores := make(framework.PluginToClusterScores, len(frw.scorePlugins))

  2. Change score logic from serial to parallel.
    It will improve performance when the number of clusters is large or there are many custom scoring plugins.

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 requested a review from Garrybest February 1, 2023 02:23
@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Feb 1, 2023
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Signed-off-by: Poor12 <[email protected]>
@Poor12 Poor12 force-pushed the improve-scheduler-performance branch from 3cb8edc to da4272d Compare February 1, 2023 09:28
}

// Option for the frameworkImpl.
type Option func(*frameworkOptions)

// WithParallelism sets parallelism for the scheduling frameworkImpl.
func WithParallelism(parallelism int) Option {
Copy link
Member

Choose a reason for hiding this comment

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

Where is this function used?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think parallelesium is a configurable parameter. So I set aside this scaffolding method.

s, res := frw.runScorePlugin(ctx, p, placement, spec, cluster)
if !res.IsSuccess() {
return nil, framework.AsResult(fmt.Errorf("plugin %q failed with: %w", p.Name(), res.AsError()))
err := fmt.Errorf("plugin %q failed with: %w", p.Name(), res.AsError())
errCh.SendErrorWithCancel(err, cancel)
Copy link
Member

Choose a reason for hiding this comment

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

errCh imports new code, how about just using a channel, like:

	errCh := make(chan error, 1)
	...
	errCh <- err
	...
	if len(errCh) > 0 {
		xxx
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, Kubernetes is also implemented in this way.

// Run NormalizeScore method for each ScorePlugin in parallel.
frw.Parallelizer().Until(ctx, len(frw.scorePlugins), func(index int) {
p := frw.scorePlugins[index]
clusterScoreList := pluginToClusterScores[p.Name()]
Copy link
Member

Choose a reason for hiding this comment

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

do we need to check whether the key exists?

Copy link
Member Author

Choose a reason for hiding this comment

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

No need. All scoring plugins have been allowed to score the cluster before. If the scoring fails, an error will be reported and this string of logic will not be entered.

Copy link
Member

@Garrybest Garrybest left a comment

Choose a reason for hiding this comment

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

Cool, almost identical as kubernetes codes.

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 10, 2023
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Garrybest
To complete the pull request process, please assign rainbowmango after the PR has been reviewed.
You can assign the PR to them by writing /assign @rainbowmango in a comment when ready.

The full list of commands accepted by this bot can be found 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants