How to make a distributed node.js application?

前端 未结 4 1610
难免孤独
难免孤独 2021-01-30 01:22

Creating a node.js application is simple enough.

var app = require(\'express\')();
app.get(\'/\',function(req,res){
    res.send(\"Hello world!\");
});
         


        
4条回答
  •  粉色の甜心
    2021-01-30 02:05

    I've been working with node for quite some time but recently got the opportunity to try scaling my node apps and have been researching on the same topic for some time now and have come across following pre-requisites for scaling:

    1. My app needs to be available on a distributed system each running multiple instances of node

    2. Each system should have a load balancer that helps distribute traffic across the node instances.

    3. There should be a master load balancer that should distribute traffic across the node instances on distributed systems.

    4. The master balancer should always be running OR should have a dependable restart mechanism to keep the app stable.

    For the above requisites I've come across the following:

    1. Use modules like cluster to start multiple instances of node in a system.

    2. Use nginx always. It's one of the most simplest mechanism for creating a load balancer i've came across so far

    3. Use HAProxy to act as a master load balancer. A few pointers on how to use it and keep it forever running.

    Useful resources:

    1. Horizontal scaling node.js and websockets.
    2. Using cluster to take advantages of multiple cores.

    I'll keep updating this answer as I progress.

提交回复
热议问题