Last active
August 27, 2017 04:09
-
-
Save wjramos/4ca41bee207c998354e1c845d001ced1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import cluster from 'cluster'; | |
import { cpus } from 'os'; | |
export function forkProcess(proc) { | |
const cores = cpus(); | |
if (cluster.isMaster) { | |
console.log(`Master ${process.pid} is running, forking process onto ${cores.length} cores`); | |
cores.forEach(core => cluster.fork()); | |
cluster.on('exit', worker => console.log(`worker ${worker.process.pid} died`)); | |
} else { | |
console.log(`App started on worker ${process.pid}`); | |
proc(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment