Created
February 16, 2020 03:34
-
-
Save mohankumar-i2i/e3fe4a25fd53d9ee647322cfa93e6a72 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 express = require("express"); | |
const numCPUs = require("os").cpus().length; | |
const app = require | |
if (cluster.isMaster) { | |
console.log(`Master ${process.pid} is running`); | |
// Fork workers. | |
for (let i = 0; i < numCPUs; i++) { | |
cluster.fork(); | |
} | |
cluster.on("exit", (worker, code, signal) => { | |
console.log(`worker ${worker.process.pid} died`); | |
}); | |
} else { | |
// Workers can share any TCP connection | |
const express = require("express"); | |
const app = express(); | |
const port = 3000; | |
app.get("/slow", (req, res) => { | |
var waitTill = new Date(new Date().getTime() + 5 * 1000); | |
while (waitTill > new Date()) {} | |
res.send("i am slow"); | |
}); | |
app.get("/fast", (req, res) => { | |
res.send("i am fast"); | |
}); | |
app.listen(port, () => console.log(`App listening on port ${port}!`)); | |
} |
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 express = require("express"); | |
const app = express(); | |
const port = 3000; | |
app.get("/slow", (req, res) => { | |
var waitTill = new Date(new Date().getTime() + 5 * 1000); | |
while (waitTill > new Date()) {} | |
res.send("i am slow"); | |
}); | |
app.get("/fast", (req, res) => { | |
res.send("i am fast"); | |
}); | |
app.listen(port, () => console.log(`App listening on port ${port}!`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment