-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
cluster: add schedulingPolicy to settings #41731
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,32 +42,37 @@ cluster.SCHED_RR = SCHED_RR; // Primary distributes connections. | |
let ids = 0; | ||
let debugPortOffset = 1; | ||
let initialized = false; | ||
|
||
// XXX(bnoordhuis) Fold cluster.schedulingPolicy into cluster.settings? | ||
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; | ||
|
||
cluster.schedulingPolicy = schedulingPolicy; | ||
let schedulingPolicy = SCHED_RR; | ||
|
||
const SCHEDULE_POLICY_NAME_MAP = new SafeMap() | ||
.set('rr', SCHED_RR) | ||
.set('none', SCHED_NONE); | ||
|
||
function processSchedulingPolicy(settings = {}) { | ||
const schedulingPolicy = process.env.NODE_CLUSTER_SCHED_POLICY || settings.schedulingPolicy; | ||
if (schedulingPolicy === 'rr' || schedulingPolicy === 'none') | ||
return schedulingPolicy; | ||
if (process.platform === 'win32') { | ||
// Round-robin doesn't perform well on | ||
// Windows due to the way IOCP is wired up. | ||
return 'none'; | ||
} | ||
return 'rr'; | ||
} | ||
|
||
cluster.setupPrimary = function(options) { | ||
const settings = { | ||
args: ArrayPrototypeSlice(process.argv, 2), | ||
exec: process.argv[1], | ||
execArgv: process.execArgv, | ||
silent: false, | ||
schedulingPolicy: cluster.schedulingPolicy || processSchedulingPolicy(options), | ||
...cluster.settings, | ||
...options | ||
}; | ||
|
||
assert(settings.schedulingPolicy); | ||
|
||
// Tell V8 to write profile data for each process to a separate file. | ||
// Without --logfile=v8-%p.log, everything ends up in a single, unusable | ||
// file. (Unusable because what V8 logs are memory addresses and each | ||
|
@@ -85,9 +90,7 @@ cluster.setupPrimary = function(options) { | |
return process.nextTick(setupSettingsNT, settings); | ||
|
||
initialized = true; | ||
schedulingPolicy = cluster.schedulingPolicy; // Freeze policy. | ||
assert(schedulingPolicy === SCHED_NONE || schedulingPolicy === SCHED_RR, | ||
`Bad cluster.schedulingPolicy: ${schedulingPolicy}`); | ||
schedulingPolicy = SCHEDULE_POLICY_NAME_MAP.get(cluster.schedulingPolicy); // Freeze policy. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be keeping the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand, it should be handled via SafeMap above: |
||
|
||
process.nextTick(setupSettingsNT, settings); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
We need to keep this (
cluster.schedulingPolicy
) and consider its value to avoid breaking things.