I am trying to launch sails.js application with cluster
library to allow it so spawn more processes to use all cores of my machine but somehow the method used with express fails here.
var cluster = require('cluster'),
numCPUs = require('os').cpus().length;
// create the server
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('worker %d died (%s). restarting...', worker.process.pid, signal || code);
cluster.fork();
});
} else {
// Start sails and pass it command line arguments
require('sails').lift(require('optimist').argv);
console.log("Sails forked");
}
After that I just normally run it via :
$ sails lift
but I get the same results when I run apache bench for this performance testing. Any help ? Am I missing something ?
EDIT
Even when I put console.log
in cluster.fork
if part then I do not get the output.
Finally I have used pm2 module for this as mentioned in one of sails
issues https://github.com/balderdashy/sails/issues/170
One should first install it:
$ npm install -g pm2
and then run the script:
$ pm2 start app.js -i max
then you can monitor it with:
$ pm2 monit
or list the processess:
$ pm2 l
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With