File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1
1
var Cookies = Npm . require ( 'cookies' ) ;
2
2
3
- var workers = process . env [ 'CLUSTER_WORKERS_COUNT' ] || 0 ;
4
- workers = new WorkerPool ( workers ) ;
3
+ var workers = null ;
4
+
5
+ // We need to start the worker pool after the server binded
6
+ // This allow use to play nicely with tools like userdown
7
+ WebApp . onListening ( function ( ) {
8
+ var workersCount = Balancer . _getWorkersCount ( ) ;
9
+ workers = new WorkerPool ( workersCount ) ;
10
+ } ) ;
5
11
6
12
Balancer . handleHttp = function handleHttp ( req , res ) {
7
13
if ( ! Cluster . discovery ) return processHereHTTP ( ) ;
@@ -109,7 +115,7 @@ function processHereHTTP() {
109
115
function processHereWS ( req , socket , head ) {
110
116
if ( process . env [ 'CLUSTER_WORKER_ID' ] ) return ;
111
117
112
- var worker = workers . pickWorker ( ) ;
118
+ var worker = workers && workers . pickWorker ( ) ;
113
119
// No worker, can't proxy. So process here.
114
120
if ( ! worker ) return false ;
115
121
Original file line number Diff line number Diff line change 1
1
var urlParse = Npm . require ( 'url' ) . parse ;
2
2
var urlResolve = Npm . require ( 'url' ) . resolve ;
3
+ var os = Npm . require ( 'os' ) ;
4
+
5
+ Balancer . _getWorkersCount = function ( ) {
6
+ var workersCount = process . env [ 'CLUSTER_WORKERS_COUNT' ] ;
7
+ if ( ( "" + workersCount ) . toLowerCase ( ) === "auto" ) {
8
+ workersCount = os . cpus ( ) . length ;
9
+ }
10
+
11
+ // We don't need to start a worker in this case
12
+ if ( workersCount == 1 ) {
13
+ workersCount = 0 ;
14
+ }
15
+
16
+ return workersCount ;
17
+ } ;
3
18
4
19
Balancer . _buildCookie = function _buildCookie ( name , service ) {
5
20
return name + "::" + service ;
You can’t perform that action at this time.
0 commit comments