The PM2 documentation — Load-balancing (cluster mode)
The built-in load-balancer provides networked Node.js applications (http(s)/tcp/udp server) to be scaled across all CPUs available, without any code modifications.
According to the PM2 documentation, PM2 also supports load-balancing across Node.js processes. Yet, the most common practice for load-balancing, inarguably, is using a load-balancing reverse proxy, such as Nginx, even if you’re using PM2.
Question
Say you have a single machine, and you’re using PM2 to make full use of multiple CPU cores spawning several Node.js processes and keep them up. Why would you use a load-balancing reverse proxy to distribute load when PM2 also supports it? Are the two “load-balancing” different things?
In other words,
why would you do
pm2 start app.js -f --3000
pm2 start app.js -f --3001
pm2 start app.js -f --3002
pm2 start app.js -f --3003
and
upstream app_servers {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3002;
}
server {
listen 80;
……
}
instead of just doing
pm2 start app.js -i max
?