Skip to content

Instantly share code, notes, and snippets.

@soarez soarez/client.js
Created Jan 31, 2016

Embed
What would you like to do?
Finding how many requests Node tries to handle at the same time for a single connection
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();
});
GET / HTTP/1.1
User-Agent: curl/7.35.0
Host: localhost:7001
Accept: */*
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
You can’t perform that action at this time.