Last active
October 31, 2018 02:50
-
-
Save WaleedAshraf/7c268c207b2af09f8dcd7275bd96cc80 to your computer and use it in GitHub Desktop.
Switching from cluster module to PM2 & RabbitMQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
const numCPUs = require('os').cpus().length; | |
module.exports.create = function(options, callback){ | |
if (cluster.isMaster) { | |
// fork child process for notif/sms/email worker | |
global.smsWorker = require('child_process').fork('./smsWorker'); | |
global.emailWorker = require('child_process').fork('./emailWorker'); | |
global.notifiWorker = require('child_process').fork('./notifWorker'); | |
// fork application workers | |
for (var i = 0; i < numCPUs; i++) { | |
var worker = cluster.fork().process; | |
console.log('worker started. process id %s', worker.pid); | |
} | |
} else { | |
callback(cluster); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment