Created
January 31, 2016 17:52
-
-
Save soarez/b68895fcf6e21b5aeba7 to your computer and use it in GitHub Desktop.
Finding how many requests Node tries to handle at the same time for a single connection
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
const net = require('net'); | |
const fs = require('fs'); | |
var req = fs.readFileSync('./req.txt', { encoding: 'utf8' }); | |
var socket = new net.Socket(); | |
socket.connect(7001, '127.0.0.1', function() { | |
console.log('Connected'); | |
var c = 50000; | |
while (c --> 0) | |
socket.write(req); | |
socket.end(); | |
}); | |
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
GET / HTTP/1.1 | |
User-Agent: curl/7.35.0 | |
Host: localhost:7001 | |
Accept: */* | |
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
const http = require('http'); | |
const util = require('util'); | |
const backlog = 2047; | |
const hostname = '0.0.0.0'; | |
const port = 7001; | |
var msg = util.format('Hello World %s %s ', port, process.pid); | |
var c = 0; | |
var h = 0; | |
http.createServer((req, res) => { | |
++h; | |
if (++c % 2 !== 0) | |
setTimeout(reply.bind(null, c), 3000); | |
else | |
reply(c); | |
function reply(c) { | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
res.end(msg + new Date() + ' ' + c); | |
--h; | |
} | |
}).listen(port, hostname, backlog); | |
setInterval(() => { console.log(h); }, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment