Skip to content

Instantly share code, notes, and snippets.

@creationix
Created February 1, 2013 22:39
Show Gist options
  • Save creationix/4694666 to your computer and use it in GitHub Desktop.
Save creationix/4694666 to your computer and use it in GitHub Desktop.
test to show that client agent throttles to 5 connections by default.
var http = require('http');
var count = 0;
function get() {
var i = count++;
console.log("Starting request #" + i);
var req = http.request({
hostname: "localhost",
port: 8080,
path: "/",
method: "GET"
}, function (res) {
console.log("Got response for request #" + i);
});
req.end();
}
for (var i = 0; i < 2000; i++) {
get();
}
var http = require('http');
var count = 0;
var server = http.createServer(function (req, res) {
var i = count++;
console.log("Received request #" + i);
setTimeout(function () {
res.writeHead(200, {
"Content-Type": "text/plain",
"Content-Length": 12
});
res.end("Hello World\n");
console.log("Sent response for request #" + i);
}, 500);
});
server.listen(8080, function () {
console.log("Server listening at http://localhost:8080");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment