简体   繁体   中英

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

My node.js server will handle 50k simultaneous clients. An single node.js server isn't able to handle such amount of load. I suppose to setup 5 or 10 node.js server running on different ports. And, have a load-balancer, eg Nginx, listening to each node.js server. When one server reach 10k clients, route the excess coming-in connections to other node.js servers. Is this the right way to handle such load with 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.

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.

This article should get you started with nginx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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