-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (39 loc) · 1008 Bytes
/
Copy pathserver.js
File metadata and controls
43 lines (39 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* LOAD APPLICATION MONITORING.
*/
// Load Newrelic
require('newrelic');
/*
* LOAD SERVER DEPEDENCIES
*/
var cluster = require('cluster');
var no_cluster = 1;
/*
* LOAD APPLICATIONS
*/
var app = require('./writeon.server');
/*
* NODE CLUSTERING
*/
// To turn off clustering, set $ process.env.NO_CLUSTER=1
if(!process.env.NO_CLUSTER && !no_cluster && cluster.isMaster) {
// Count the machine's CPUs
var count = require('os').cpus().length;
// Create a worker for each CPU
for(var i = 0; i < count; i++) {
cluster.fork();
}
cluster.on('exit', function() {
console.log('Worker died. Spawning a new process...');
cluster.fork();
});
cluster.on('fork', function(worker) {
console.log('Worker ' + worker.id + ' is now running.');
});
} else {
// Listen on port 3000
var port = process.env.PORT || 3000;
app.listen(port, null, function() {
console.log('Server started: http://localhost:' + port);
});
}