Created
December 1, 2018 12:46
-
-
Save MuhammadHasham23/c920d2108ee266ab4f2ab903e9fabe77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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