TL;DR
If it's just pm2
vs. nginx
go for nginx. Better: both. Best: a even broader setup.
If you want the most mature load balancing features use HAProxy
. It's do one thing best. You'll get SSL-termination, ACLs and it being very lightweight. I can't prove with numbers, but I feel it has the lowest hit on http requests. A good read is this.
If you also need to serve (at least some) static content your goto option is nginx
for its superior capabilities in this field. Also of your list it's the only one to provide such a feature. Except for node
itself, but doing it very poorly.
pm2
feels very heavy-weight IMO and tends to break more often. It's capabilities of process load balancing are very good and secures uptime of your node process. It abstracts cluster
.
cluster
feels just 'being fixed' to a bare minimum. In the past and maybe still the os-level support lead to different behaviours on different platforms. For example, bias to single processes.
My current setup is:
HAProxy
for cluster wide loadbalancing, including balancing several instances of a process per machine
- CDN for static content (e.g. Cloudinary)
pm2
for process load balancing
nginx
not suffer the same issues? It has three different load balancing modes, none of which takes into account the 'resource needs' of each connection. – Peevedfork_mode
instead of thecluster
. The pm2 cluster is nothing else than the node cluster under the hood. – Boulevardiernginx
and cluster both for load balancing? From what I know, withnginx
you have to specify different ports to different instances of the same application, whereas with cluster you have all the instances listening to the same socket but spawning different threads. – Peevednginx
andpm2
in afork mode
for example. – Boulevardier