Search code examples
node.jspm2

For a 2 core machine, will it help to set 4 processes with pm2?


Using pm2 with node.js app, 2 core machine.

pm2 start app.js -i 4

Will it help the performance, or won't help at all ?

Thanks !


Solution

  • It won't help performance, in fact it will be harmful. It's recommended to spawn N-1 workers, N being the amount of CPU cores.

    You can issue: pm2 start app.js -i -1 for that. Given that you only have 2 cores, this will only use one, so you won't take advantage of clustering.

    If you want to try using 2 cores in your case, you should run your own benchmarks, but make sure that your machine is not doing much work outside of Node.js, otherwise it will be better to just use 1 core.

    If you use more workers than CPU cores, the processes will start competing for resources, which will downgrade the performance of the application.