Skip to content

Instantly share code, notes, and snippets.

@markdaws
Created February 13, 2012 00:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markdaws/1812229 to your computer and use it in GitHub Desktop.
Save markdaws/1812229 to your computer and use it in GitHub Desktop.
Default connection pool behaviour
var http = require('http');
var concurrentServerRequests = 0;
var totalServerRequests = 0;
var PORT_BASE = 1337;
function createServer(host, port) {
http.createServer(function (req, res) {
++concurrentServerRequests;
++totalServerRequests;
console.log('Concurrent active server requests:' +
concurrentServerRequests + ', total received:' +
totalServerRequests);
setTimeout(function() {
--concurrentServerRequests;
res.end();
}, Math.random() * 3000);
}).listen(port, host);
console.log('Server running at http://' + host + ':' + port);
}
function runTestCase1() {
createServer('127.0.0.1', PORT_BASE);
for(var i=0;i<100; ++i) {
http.request({
host: '127.0.0.1',
port: PORT_BASE,
method: 'GET'
}, function(res) {
}).end();
}
}
runTestCase1();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment