Node Cluster and Nginx Reverse Proxy

October 10, 2014 0 Comments by

Load balancing for durability and performance with clustering and reverse proxy servers

Using clusters is a form of load balancing, as is implementing a reverse proxy server.

Node applications run on a single thread. To achieve multi-threading we spawn multiple processes controlled a by a master node. These child nodes, or clusters, are servers. All requests are answered by the master node. The master node doesn’t serve the application. It pushes the requests to clusters in a round robin fashion.

With this implementation, a large load can be handled by a single server, which spawns multiple server processes. This increases durability. Every request that comes into the application could potentially throw an error or exception. These exceptions should be handled in the application code. If the exception is not handled, or caught, then the server will stop responding. Additional requests coming into the server will not be served. Users won’t be able to access the site because the server has crashed. Implementing clustering means that although one server has crashed, there are other server processes running that can serve new requests. The master node will take care of this. It will bring the crashed server process down gracefully, or shut it down forcefully. When this is complete it will start another server in a new process, so that the configured amount of child server processes will always be consistent.

Node clustering is often used with multi-core processors. The number of CPUs can be used to determine how many child clusters to launch. Multiple node clusters can be deployed on a single-core processor.

Tag cloud