Skip to content

Instantly share code, notes, and snippets.

@MuhammadHasham23
Created December 1, 2018 12:46
Show Gist options
  • Save MuhammadHasham23/c920d2108ee266ab4f2ab903e9fabe77 to your computer and use it in GitHub Desktop.
Save MuhammadHasham23/c920d2108ee266ab4f2ab903e9fabe77 to your computer and use it in GitHub Desktop.
const cluster = require ('cluster');
const os = require ('os');
if (cluster.isMaster) {
const cpus = os.cpus ().length;
console.log (`Forking for ${cpus} CPUs`);
for (let i = 0; i < cpus; i++) {
cluster.fork ();
}
Object.values (cluster.workers).forEach (worker => {
worker.send (`Hello Worker ${worker.id}`);
});
} else {
require ('./server');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment