Created
July 14, 2021 15:55
-
-
Save foyzulkarim/cd2f6ba229efe42307ba6282384c3d53 to your computer and use it in GitHub Desktop.
Webinar on Node.js : Express.js handle 200K+ request in 10seconds using Cluster and PM2
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') | |
var numCPUs = require('os').cpus().length; | |
const cluster = require('cluster'); | |
const app = express() | |
app.get('/', (req, res) => { | |
res.send('Hello World!') | |
}); | |
const doClustering = false; | |
if (cluster.isMaster && doClustering) { | |
for (let i = 0; i < numCPUs; i++) { | |
cluster.fork(); | |
} | |
cluster.on('death', function (worker) { | |
logger.info('worker ' + worker.pid + ' died'); | |
}); | |
} else { | |
app.listen(3000, () => { | |
console.log('Example app listening on port 3000!') | |
}) | |
} |
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
{ | |
"name": "fblive", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start:nodemon": "nodemon index.js", | |
"ac": "autocannon -c 12 http://localhost:3000", | |
"pm2start": "pm2 start index -i max", | |
"pm2stop": "pm2 stop index", | |
"pm2monit": "pm2 monit" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"autocannon": "^7.4.0", | |
"express": "^4.17.1", | |
"nodemon": "^2.0.12", | |
"pm2": "^5.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment