Skip to content

Instantly share code, notes, and snippets.

@shuhei
Created June 25, 2018 22:33
Show Gist options
  • Save shuhei/b3b79ef6ed6022ba6a714c74f4dfd69e to your computer and use it in GitHub Desktop.
Save shuhei/b3b79ef6ed6022ba6a714c74f4dfd69e to your computer and use it in GitHub Desktop.
Node.js Thread Pool test
UV_THREADPOOL=100 node index.js
ab -c 100 -n 1000
htop
const http = require('http');
const cluster = require('cluster');
const fs = require('fs');
if (cluster.isMaster) {
for (let i = 0; i < 4; i++) {
cluster.fork();
}
} else {
createServer();
}
function createServer() {
const server = http.createServer((req, res) => {
fs.readFile('photo.png', (err, data) => {
if (err) {
res.writeHead(500, {
'Content-Type': 'text/plain',
});
res.end(`error ${err.toString()}`);
return;
}
res.writeHead(200, {
'Content-Type': 'image/png',
});
res.end(data);
});
});
server.listen(8080);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment