Skip to content

Instantly share code, notes, and snippets.

Avatar

Anthony Ettinger chovy

View GitHub Profile
@learncodeacademy
learncodeacademy / cluster.md
Created Oct 9, 2014
Node Cluster - Enhance your node app by using all the cores of your processor.
View cluster.md

Here's all you have to do to add clustering to your node.js application.

  • save this code as cluster.js, and run cluster.js instead of server.js (or /bin/www, or whatever it's called for your project)
  • the only line you'll need to change is the last line - it needs to point to the location of your server.js file
var cluster = require('cluster');

if (cluster.isMaster) {
  // Count the machine's CPUs
  var cpuCount = require('os').cpus().length;
You can’t perform that action at this time.