Created
August 6, 2020 10:08
-
-
Save Neilblaze/960e903a4d1cba7ab29b8efd9e85110c to your computer and use it in GitHub Desktop.
NCM load-balancer // archived
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() | |
} | |
} else { | |
require('./server') | |
} |
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 http = require('http') | |
const pid = process.pid | |
http | |
.createServer((req, res) => { | |
for (let i = 0; i < 1e7; i++); // CPU work simulation | |
res.end(`Handled by process ${pid}`) | |
}) | |
.listen(8080, () => { | |
console.log(`Started process ${pid}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment