Nodejs中的负载平衡 [英] Load Balancing in Nodejs
问题描述
我最近从节点开始,我已经读了很多关于它是单线程的限制以及它如何不利用您的内核的知识,然后我读了这篇文章
I recently started with node and I have been reading a lot about its limitation of it being single threaded and how it does not utilise your cores and then I read this
http://bit.ly/1n2YW68 (其中讨论了新的集群 >用于负载均衡的nodejs模块)
http://bit.ly/1n2YW68 (which talk about the new cluster module of nodejs for loadbalancing)
现在,我不确定我是否完全同意:),因为在开始使用节点之前,我想到的第一件事就是如何通过网络服务器使用节点,使其具有适当的负载平衡,例如上游模块,如nginx
Now I'm not sure I completely agree to it :) because the first thing that I thought of before starting with node on how to make it utilise cores with proper load balancing is via web-server some like upstream module like nginx
喜欢做这样的事情
upstream domain1 {
server http://nodeapp1;
server http://nodeapp2;
server http://nodeapp3;
}
所以我的问题是,使用这种群集模块进行负载平衡以利用内核是否有优势,它比Web服务器负载平衡有任何显着优势吗? 还是博客帖子与实际使用相距太远.
So my question is there an advantage to use such cluster module for load balancing to utilise the cores does it has any significant advantage over web server load balancing or is blog post too far from real use.
注意:我并不关心各种应用服务器(如passenger)的负载平衡处理(乘客也支持nodejs,但我不想寻找答案:))我已经知道了,因为我主要是红宝石程序员
Note: I'm ain't concerned about load balancing handle by various app server like passenger(passenger has nodejs support as well but something that I'm not looking for answer :)) which I already know since I'm mostly a ruby programmer
推荐答案
可用于对NodeJs应用程序进行集群的另一个选项是使用PM2部署应用程序.
One other option you can use to cluster NodeJs applications is to deploy the app using PM2.
集群非常简单,您无需手动实现集群
pm2 start app.js -i max
PM2是自动检测可用CPU数量并运行尽可能多进程的专家
PM2 is an expert to auto detect the number of available CPUs and run as many processes as possible
在此处了解PM2集群模式 http://pm2.keymetrics.io/docs/usage/cluster-mode/
Read about PM2 cluster mode here http://pm2.keymetrics.io/docs/usage/cluster-mode/
为了控制IO操作的负载,我使用备忘录概念编写了一个名为QueueP的库.您甚至可以自定义备忘录逻辑并获得超过10的加速值,有时
For controlling the load of IO operations, I wrote a library called QueueP using the memoization concept. You can even customize the memoization logic and gain speedup values of more than 10, sometimes
https://www.npmjs.com/package/queuep
这篇关于Nodejs中的负载平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!