-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (31 loc) · 915 Bytes
/
server.js
File metadata and controls
41 lines (31 loc) · 915 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
/*
Created by Kailas Walldoddi <@kailashw on github.com>
Creating clusters and serving an application that uses express
*/
'use strict';
// importing the modules
const cluster = require('cluster'),
os = require('os').cpus().length,
server = require('./serverHttp');
/*
We see if it is the master cluster in case it is,
we will clone the cluster amount at the same time as the cores
of the processor.
*/
if(cluster.isMaster){
const Master = require('./work');
const master = new Master({cluster:cluster});
for(let i = 0; i < os; i++){
master.liftWorker();
}
cluster.on('exit', (worker)=>{
console.log(worker)
console.log(`The Worker number: ${worker.id} is dead.`);
master.liftWorkerError();
});
}else{
// Creando un servidor con http y express
let app = new server();
app.initiate();
console.log(`cluster ${cluster.worker.id} is running.`)
}