Search code examples
node.jsexpressnode-cluster

How to use node's cluster module in an express website?


I've read a little bit about the cluster module introduced in Node.js 0.8, but I'm not really sure how to go about (or whether I should) apply it to my website running on Express. I have a pretty vanilla Express set-up: templates rendered by Hogan.js, CSS compiled by Stylus, no websockets or fancy middleware.

Are there significant performance improvements to be gained by using the cluster module?

If so, how best to go about using cluster in a standard Express project?


Solution

  • As it happens, I blogged about this just yesterday! In answer to your performance question – yes, there is a definite benefit. I included a few benchmarks in my post:
    http://rowanmanning.co.uk/posts/node-cluster-and-express

    The short answer is that the cluster module allows you to take full advantage of a mutli-core machine; your app will be able to handle considerably more requests.

    It's also worth reading this answer, which details Nginx as an alternative:
    Node.js on multi-core machines