Search code examples
javascriptnode.jspm2

Node js cluster and pm2 cluster


So I am running a service in node which has a node js cluster usage meaning I am running the service with node js clusters... now I want to use pm2 and I use the pm2 cluster mode. I wonder if it's a good thing to use both of them at the same time or should I use only one of them for better performance and stuff like that... Any help would be appreciated


Solution

  • To take the complexity out of your architecture I would recommend to use PM2. It lets you efficiently manage multiple processes. It has many features including:

    • Auto restart an app, if there is any change in code with Watch & Reload.
    • An easy log management for processes.
    • Monitoring capabilities of the process.
    • An auto restart if the system reaches max memory limit or it crashes.
    • Keymetrics monitoring over the web.

    As the processes are separated, now can start/stop/restart them with your pm2.config.js, i.e

    pm2 start pm2.config.js // start all processes
    pm2 stop app // stop app processes
    pm2 restart smsWorker // restart smsWorker