what is the right way to start multiple node instances on a multi core server?

I have a nodejs app that i want to run on a multi core (2CPU * 2Cores = 4Cores) server. After reading thru a bunch of SO threads on this topic, I have decided to start 4 separate node instances on 4 different ports and use nginx to load balance among them. I decided to use this approach over node cluster.

Now here are my questions. I would really appreciate any feedback:

  1. Is there any difference in how one would start 4 node instances on a 2cpu * 2cores/cpu = 4 core server vs. 1cpu * 4cores/cpu = 4core server. I dont think there is any difference, but just wanted to confirm.

  2. I have a conf file to start my service. This conf file is actually a script that resides in /etc/init and starts my node app. Should I start the 4 instances from this 1 conf file or should I create 4 conf file and start one instance per conf file. Again, I feel the latter approach is better, but wanted to confirm it.

Why have you decided to:

  1. use nginx to load balance? haproxy is a better solution for this purpose.
  2. manually start n processes when there's a cluster module that does that for you?

    If you start n different processes you'll need to listen to n different ports.

    If you use the cluster module you don't need any load balancer because this job is done internally and the n workers will listen to the same port. If a worker dies you get a notification and basically you can manage them easily.

All the workers can open/read/write/close the same file, you don't need n config files.

  1. 1 instance per core is a good rule of thumb, but if you also run some services on the same server (database, redis, memcache, queue, ...), you may want start less instances so these don't "fight" for the cpu.

  2. You eventually going to need to restart individual instances because one crashed, or is using too much memory, or what not. So separate scripts would be preferable, or even a script that allow you to control instances separately or together (which is more work initially).