I’m evaluating nodejs for small portion of our web application where it seems like it would be a good fit. I know that node is young and moving fast, but it seems like it has finally gotten to the “ready for production category”. However, googling around, most information I see on production deployments are a year old and still warn about how fragile node can be and can error out unexpectedly, followed by some solutions to restart. This doesn’t scare me away by itself, but there seems to be lack of official word on “the right way” to put node out there reliably.
I’m evaluating nodejs for small portion of our web application where it seems like
Share
clusterseems to be a good option, although depending on your OS it might have poor load-balancing performance. A very simple version would be something like this:This is a nice option because it both gives you some stability by restarting dead processes, and gives you multiple processes that share the load. Note that
clusterbasically modifies server.listen so that workers are all listening to events coming from the master, which is doing the listening. This is where the “free” load-balancing comes from.Cluster documentation can be found here: http://nodejs.org/api/cluster.html
It may also be worth having the master process handle a couple of signals if you want to be able to trigger certain events, such as killing and restarting all the processes, or killing all the processes and shutting down.