From 4985a2e6a64b70eaf58add244d740ab25e500228 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. --- 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 dc8efc1f98e56b..5a83546fa14b0b 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;