Run webapp on more than 1 thread

This commit is contained in:
samcm 2017-12-30 13:23:08 +11:00
parent adcbc40673
commit 549a58ac2d
1 changed files with 22 additions and 4 deletions

View File

@ -179,14 +179,32 @@ function killOldInvites(){
})
}
killOldInvites()
setInterval(() => {
killOldInvites()
}, 3600000)
var shortenedLinks = {}
loadFromFile((result) => {
shortenedLinks = result
rootserver.listen(PORT);
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
setInterval(() => {
if (cluster.isMaster) {
killOldInvites()
}
}, 3600000)
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', (thread, code, signal) => {
console.log(`thread ${thread.process.pid} died`, code, signal)
});
} else {
rootserver.listen(PORT)
}
})
console.log('SyncLounge WebApp successfully started on port ' + PORT)