简体   繁体   English

自节点v0.12.2以来的负载平衡 - 集群,pm2或nginx

[英]Load balancing since Node v0.12.2 - cluster, pm2 or nginx

With Node v0.12.2, the cluster module supports Round-Robin (RR) load balancing , which ensures load is more evenly distributed than the previous OS-level load balancing. 通过Node v0.12.2,集群模块支持Round-Robin(RR)负载均衡 ,可确保负载比以前的OS级负载均衡更均匀地分布。

So now we are spoilt for choice: 所以现在我们被宠坏了选择:

  1. Use the cluster module 使用群集模块
  2. Use pm2 which uses the cluster module under the hood 使用pm2 ,它使用引擎盖下的集群模块
  3. Use nginx 使用nginx
  4. Use HAProxy 使用HAProxy

I am aware of this excellent post as well as other answers here on SO, but none have addressed the newer Cluster module with RR mode. 我知道这个优秀的帖子以及SO上的其他 答案 ,但是没有人用RR模式解决了较新的Cluster模块。 So the question boils down to: 所以问题归结为:

Judging only on their load balancing capabilities, should I use pm2 or nginx ? 仅根据其负载均衡功能判断,我应该使用pm2还是nginx

TL;DR TL; DR

If it's just pm2 vs. nginx go for nginx. 如果只是pm2nginx那就去找nginx吧。 Better : both. 更好 :两者。 Best : a even broader setup. 最佳 :更广泛的设置。

If you want the most mature load balancing features use HAProxy . 如果您想要最成熟的负载均衡功能,请使用HAProxy It's do one thing best . 这是最好一件事 You'll get SSL-termination, ACLs and it being very lightweight. 您将获得SSL终止,ACL并且它非常轻量级。 I can't prove with numbers, but I feel it has the lowest hit on http requests. 我不能用数字证明,但我觉得它对http请求的命中率最低。 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. 如果您还需要提供(至少某些)静态内容,则您的goto选项是nginx因为它在此字段中具有卓越的功能。 Also of your list it's the only one to provide such a feature. 您的列表中也是唯一一个提供此类功能的人。 Except for node itself, but doing it very poorly. 除了node本身,但做得很差。

pm2 feels very heavy-weight IMO and tends to break more often. pm2感觉非常重量级的IMO并且往往会更频繁地断裂。 It's capabilities of process load balancing are very good and secures uptime of your node process. 它的流程负载平衡功能非常好,可确保节点进程的正常运行时间。 It abstracts cluster . 它抽象cluster

cluster feels just 'being fixed' to a bare minimum. cluster感觉只是“被修复”到最低限度。 In the past and maybe still the os-level support lead to different behaviours on different platforms. 在过去,也许os级别的支持导致不同平台上的不同行为。 For example, bias to single processes. 例如,偏向单个过程。

My current setup is: 我目前的设置是:

  • HAProxy for cluster wide loadbalancing, including balancing several instances of a process per machine 用于群集范围负载平衡的HAProxy ,包括平衡每台计算机的多个进程实例
  • CDN for static content (eg Cloudinary ) 静态内容的CDN(例如Cloudinary
  • pm2 for process load balancing pm2用于进程负载平衡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM