Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right way to start multiple Node instances on a multi core server? [closed]

I have a Node.js app that I want to run on a multi core (2CPU * 2Cores = 4Cores) server. After reading through a bunch of Stack Overflow 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.

Here are my questions that I'm trying to answer:

  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 don't 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.

like image 579
Silent User Avatar asked Dec 14 '25 15:12

Silent User


1 Answers

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.

like image 197
Gabriel Llamas Avatar answered Dec 17 '25 19:12

Gabriel Llamas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!