-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathapp.js
33 lines (27 loc) · 835 Bytes
/
app.js
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
const cluster = require('cluster');
const os = require('os');
const path = require('path');
const fs = require('fs');
// break default setting on windows
cluster.schedulingPolicy = cluster.SCHED_RR;
// create a folder by name test_images to keep images
const uploadDir = path.join(__dirname, "test_images");
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir);
}
if (cluster.isMaster) {
const machineCPU = os.cpus().length;
console.log(`Work will be balanced between:${machineCPU} CPU cores`)
for (let i = 0; i < machineCPU; i++) {
cluster.fork();
}
cluster.on('exit', function (worker, code, signal) {
if (worker.suicide === true) {
console.log(new Date() + ' Worker committed suicide');
cluster.fork();
}
});
}
else {
require('./server');
}