简体   繁体   English

如何使用node.js服务器处理大量负载?

[英]How to handle large amount of load with node.js server?

My node.js server will handle 50k simultaneous clients. 我的node.js服务器将处理5万个并发客户端。 An single node.js server isn't able to handle such amount of load. 单个node.js服务器无法处理这样的负载量。 I suppose to setup 5 or 10 node.js server running on different ports. 我想设置在不同端口上运行的5或10个node.js服务器。 And, have a load-balancer, eg Nginx, listening to each node.js server. 并且,有一个负载均衡器,例如Nginx,监听每个node.js服务器。 When one server reach 10k clients, route the excess coming-in connections to other node.js servers. 当一台服务器达到10k客户端时,将多余的即将到来的连接路由到其他node.js服务器。 Is this the right way to handle such load with node.js? 这是使用node.js处理此类负载的正确方法吗? If not, what's the best practice? 如果没有,最佳做法是什么?

The most simple way to handle the load is indeed to use a load balancer to forward the requests to different server on the same machine or on remote machines. 处理负载的最简单方法是使用负载均衡器将请求转发到同一台机器或远程机器上的不同服务器。

If you would to setup the servers only on one machine, use pm2 , it will take care of the load balancing and keeping your server instances alive. 如果您只在一台计算机上设置服务器,请使用pm2 ,它将负责负载平衡并使您的服务器实例保持活动状态。

Be aware that running on one machine doesn't give you high availability and in case of a random shutdown your service will be down. 请注意 ,在一台计算机上运行并不能提供高可用性,如果随机关闭,您的服务将会关闭。

I would advise running the server on multiple one-core machines than on one multiple-core machine. 我建议在多个单核机器上运行服务器,而不是在一台多核机器上运行。 In order to do so, setup pm2 / forever on each machine and another machine for running nginx for load balancing. 为此,请在每台计算机和另一台计算机上设置pm2 / forever以运行nginx以进行负载平衡。

This article should get you started with nginx. 本文应该让您开始使用nginx。

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

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