3

I understand that PM2 Cluster Mode allows us to easily scale across CPUs on a single machine. Does it create multiple instances of the node application it is scaling? Essentially, is it the same thing as running multiple node applications on different ports with a reverse proxy like Nginx?

Then, there's Node Cluster which forks a child process. Is this approach more efficient compared to PM2 Cluster Mode as it is running a single Node Application and using worker threads to process incoming requests?

Nick
  • 4,002
  • 4
  • 30
  • 41

1 Answers1

4

they basically do the same, PM2 will use Node Cluster under the hood, it will make things easier since you don't have to programmatically handle forking in your code, just run it as is.

note that Cluster Mode will not support session stickiness so make sure your app is stateless.

Daniel Miron
  • 460
  • 3
  • 14
  • I'm probably going to have to test this out, but I'm trying to understand if the resource usage would go up proportionally to the number of forks PM2 makes. For instance, if a single instance of the app used 4GB, in PM2 each additional instance would consume another 4GB whereas in Node Cluster, it will not. – Nick Aug 12 '17 at 09:39
  • 3
    I just discovered that forking in Node is very different than a POISIX fork in that it doesn't actually clone the current process, but it does start up a new V8 instance. Source: http://stackabuse.com/setting-up-a-node-js-cluster/ – Nick Aug 13 '17 at 11:26