diff --git a/webapp.js b/webapp.js index 02d36567..64015cc3 100644 --- a/webapp.js +++ b/webapp.js @@ -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)