Created
February 13, 2012 00:41
-
-
Save markdaws/1812229 to your computer and use it in GitHub Desktop.
Default connection pool behaviour
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
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