lib: refactored scheduling policy assignment

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: https://github.com/nodejs/node/pull/32663
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Yash Ladha authored and Shelley Vohr committed 2020-05-11 09:56:47 -07:00
1 parent 548cedd870
commit 94d0a088ec
1 file changed
+11 -10
+11 -10
View File
@@ -37,16 +37,17 @@ let debugPortOffset = 1;
let initialized = false;
// XXX(bnoordhuis) Fold cluster.schedulingPolicy into cluster.settings?
let schedulingPolicy = {
'none': SCHED_NONE,
'rr': SCHED_RR
}[process.env.NODE_CLUSTER_SCHED_POLICY];
if (schedulingPolicy === undefined) {
// FIXME Round-robin doesn't perform well on Windows right now due to the
// way IOCP is wired up.
schedulingPolicy = (process.platform === 'win32') ? SCHED_NONE : SCHED_RR;
}
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;