Scaling node.js server instances on the same machine

Running a web server on node.js is a simple matter (as can be seen from its excellent examples and documentation), but I wonder how you can fully utilize the processor resources of a dedicated server?

Since node.js is single-threaded, the only way to take advantage of multiple processors is through multiple processes. Of course, only one process can bind to the port, so it seems that there should be a master / worker template in which the wizard expands the children, binds to the incoming port and delegates incoming connections (and actual processing) to the children, (Perhaps, through the hungry consumer pattern ?)

Is this the best way to scale a web server with node.js? If so, are there libraries to simplify the master / worker template? If not, which deployment templates or installations are recommended for the best use of all the resources of a dedicated machine?

(Is this the best question for ServerFault ?)

+7
source share
2 answers

Multi-node is a library that provides a master / worker template.

If server processes should not be able to talk to each other and you are not using Socket.IO , a simple option is to simply start one process / kernel, bind to local ports and use something like nginx or HAProxy to load balance between them.

+6
source

If you use express, I would use tj Cluster: http://learnboost.github.com/cluster/

It provides a "transparent" processor-based load balancing, which is nice because you can use an existing express application, and it scales it across the cores relatively painlessly.

+2
source

All Articles