@@ -42,32 +42,37 @@ cluster.SCHED_RR = SCHED_RR; // Primary distributes connections.
42
42
let ids = 0 ;
43
43
let debugPortOffset = 1 ;
44
44
let initialized = false ;
45
-
46
- // XXX(bnoordhuis) Fold cluster.schedulingPolicy into cluster.settings?
47
- let schedulingPolicy = process . env . NODE_CLUSTER_SCHED_POLICY ;
48
- if ( schedulingPolicy === 'rr' )
49
- schedulingPolicy = SCHED_RR ;
50
- else if ( schedulingPolicy === 'none' )
51
- schedulingPolicy = SCHED_NONE ;
52
- else if ( process . platform === 'win32' ) {
53
- // Round-robin doesn't perform well on
54
- // Windows due to the way IOCP is wired up.
55
- schedulingPolicy = SCHED_NONE ;
56
- } else
57
- schedulingPolicy = SCHED_RR ;
58
-
59
- cluster . schedulingPolicy = schedulingPolicy ;
45
+ let schedulingPolicy = SCHED_RR ;
46
+
47
+ const SCHEDULE_POLICY_NAME_MAP = new SafeMap ( )
48
+ . set ( 'rr' , SCHED_RR )
49
+ . set ( 'none' , SCHED_NONE ) ;
50
+
51
+ function processSchedulingPolicy ( settings = { } ) {
52
+ const schedulingPolicy = process . env . NODE_CLUSTER_SCHED_POLICY || settings . schedulingPolicy ;
53
+ if ( schedulingPolicy === 'rr' || schedulingPolicy === 'none' )
54
+ return schedulingPolicy ;
55
+ if ( process . platform === 'win32' ) {
56
+ // Round-robin doesn't perform well on
57
+ // Windows due to the way IOCP is wired up.
58
+ return 'none' ;
59
+ }
60
+ return 'rr' ;
61
+ }
60
62
61
63
cluster . setupPrimary = function ( options ) {
62
64
const settings = {
63
65
args : ArrayPrototypeSlice ( process . argv , 2 ) ,
64
66
exec : process . argv [ 1 ] ,
65
67
execArgv : process . execArgv ,
66
68
silent : false ,
69
+ schedulingPolicy : cluster . schedulingPolicy || processSchedulingPolicy ( options ) ,
67
70
...cluster . settings ,
68
71
...options
69
72
} ;
70
73
74
+ assert ( settings . schedulingPolicy ) ;
75
+
71
76
// Tell V8 to write profile data for each process to a separate file.
72
77
// Without --logfile=v8-%p.log, everything ends up in a single, unusable
73
78
// file. (Unusable because what V8 logs are memory addresses and each
@@ -85,9 +90,7 @@ cluster.setupPrimary = function(options) {
85
90
return process . nextTick ( setupSettingsNT , settings ) ;
86
91
87
92
initialized = true ;
88
- schedulingPolicy = cluster . schedulingPolicy ; // Freeze policy.
89
- assert ( schedulingPolicy === SCHED_NONE || schedulingPolicy === SCHED_RR ,
90
- `Bad cluster.schedulingPolicy: ${ schedulingPolicy } ` ) ;
93
+ schedulingPolicy = SCHEDULE_POLICY_NAME_MAP . get ( cluster . schedulingPolicy ) ; // Freeze policy.
91
94
92
95
process . nextTick ( setupSettingsNT , settings ) ;
93
96
0 commit comments