简体   繁体   中英

Nodejs Cluster Master failover

I m designing a cluster using Node JS server. I read on documentation that the NodeJS clustering is made up on same server, using mainly worker processes according to the number of processors the server has. My question is about a failover mechanism able to keep my application to works even if the Master process crashes down.

What is the best practice in this situation?

I can give you a few suggestions based on the Node.js projects that I've worked on.

  1. Use a cache mechanism like Redis (use it as a LRU cache) or MemCache temporarily store communication data and later persist it somewhere. This way even if the server crashes you can still recover data from the Cache when server restarts.
  2. Use PM2 or forever to monitor your Node.js instance and restart it upon crash.
  3. Keep your server stateless so that you shouldn't be worrying about storing client's context on the server (master or slave processes).
  4. If it is a big app, you can use nginx to load balance between server instances and also setup it in a way that it shifts load to other servers in case of a crash.

Hope this helps.

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