From 94d0a088ec159fc7fbbda39135fcc491126ee2f0 Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Sun, 5 Apr 2020 12:15:53 +0530 Subject: [PATCH] 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 Reviewed-By: Ruben Bridgewater Reviewed-By: Matteo Collina --- lib/internal/cluster/master.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/internal/cluster/master.js b/lib/internal/cluster/master.js index 9d6d4df6316956..9e2c7cbecb9963 100644 --- a/lib/internal/cluster/master.js +++ b/lib/internal/cluster/master.js @@ -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;