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

lib: refactored scheduling policy assignment #32663

Closed

Conversation

yashLadha
Copy link
Member

In previous implementation it was clubbed into declaration of scheduling
policies and fetching the schedulingPolicy. Now they are separate
variables, so that in future if one want to add new scheduling policy.
It is much simpler and not obsfucated.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the cluster Issues and PRs related to the cluster subsystem. label Apr 5, 2020
};

// XXX(bnoordhuis) Fold cluster.schedulingPolicy into cluster.settings?
let { [process.env.NODE_CLUSTER_SCHED_POLICY]: schedulingPolicy } = schedulingPolicies;
Copy link
Contributor

Choose a reason for hiding this comment

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

lint-js rule check error is triggered :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, my bad. Done 👍

@yashLadha yashLadha force-pushed the chore/destructure_scheduling_policy branch from c93cf14 to 2579e7f Compare April 5, 2020 08:49
@Trott
Copy link
Member

Trott commented Apr 13, 2020

@nodejs/cluster

@bnoordhuis
Copy link
Member

I'm really rather lukewarm when it comes to changes like this one. I might be biased because I wrote the current code but the new code is arguably less readable than the code it replaces.

@yashLadha
Copy link
Member Author

yashLadha commented Apr 13, 2020

@bnoordhuis is it specific to destructuring or the naming. Just wanted to know the cause 😄

@bnoordhuis
Copy link
Member

The destructuring. It's not that it's incredibly complex or difficult to follow, just harder to parse than the current code (IMO.)

@yashLadha
Copy link
Member Author

@bnoordhuis what should be the correct approach then according to you, because previously we are pulling the scheduling policy straight out from the hash which is not implying anything in general. 🤔

@bnoordhuis
Copy link
Member

Well, if you want to make an improvement, how about this?

let schedulingPolicy = process.env.NODE_CLUSTER_SCHED_POLICY;
if (schedulingPolicy === 'rr')
  schedulingPolicy = SCHED_RR;
else if (schedulingPolicy === 'none')
  schedulingPolicy = SCHED_NONE;
else if (process.platform === 'win32')
  // Round-robin doesn't perform well on Windows due to the way IOCP is wired up.
  schedulingPolicy = SCHED_NONE;
else
  schedulingPolicy = SCHED_RR;

That at least protects schedulingPolicy from jokers setting NODE_CLUSTER_SCHED_POLICY to __proto__ , constructor, etc.

It's a marginal improvement but marginal improvements are improvements too. :-)

@yashLadha yashLadha force-pushed the chore/destructure_scheduling_policy branch from 2579e7f to bc2ba78 Compare April 13, 2020 14:00
In previous implementation it was clubbed into declaration of scheduling
policies and fetching the schedulingPolicy. Now they are separate
variables, so that in future if one want to add new scheduling policy.
It is much simpler and not obsfucated.
@yashLadha yashLadha force-pushed the chore/destructure_scheduling_policy branch from bc2ba78 to 4985a2e Compare April 13, 2020 14:25
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 7, 2020
@nodejs-github-bot
Copy link
Collaborator

addaleax pushed a commit that referenced this pull request May 9, 2020
In previous implementation it was clubbed into declaration of scheduling
policies and fetching the schedulingPolicy. Now they are separate
variables, so that in future if one want to add new scheduling policy.
It is much simpler and not obsfucated.

PR-URL: #32663
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@addaleax
Copy link
Member

addaleax commented May 9, 2020

Landed in 023bcde

@addaleax addaleax closed this May 9, 2020
codebytere pushed a commit that referenced this pull request May 11, 2020
In previous implementation it was clubbed into declaration of scheduling
policies and fetching the schedulingPolicy. Now they are separate
variables, so that in future if one want to add new scheduling policy.
It is much simpler and not obsfucated.

PR-URL: #32663
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@codebytere codebytere mentioned this pull request May 18, 2020
codebytere pushed a commit that referenced this pull request Jun 7, 2020
In previous implementation it was clubbed into declaration of scheduling
policies and fetching the schedulingPolicy. Now they are separate
variables, so that in future if one want to add new scheduling policy.
It is much simpler and not obsfucated.

PR-URL: #32663
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@codebytere codebytere mentioned this pull request Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. cluster Issues and PRs related to the cluster subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants