Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created August 2, 2011 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/1119591 to your computer and use it in GitHub Desktop.
Save dominictarr/1119591 to your computer and use it in GitHub Desktop.
script to check level of concurrency through proxy
var util = require('util'),
colors = require('colors'),
http = require('http'),
httpProxy = require('./../lib/node-http-proxy');
//
// Basic Http Proxy Server
//
httpProxy.createServer(9000, 'localhost').listen(8000);
//
// Target Http Server
//
// to check apparent problems with concurrent connections
// make a server which only responds when there is a given nubmer on connections
//
var connections = []
, go
, CONCURRENT = 10
http.createServer(function (req, res) {
connections.push (function (){
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
})
process.stdout.write(connections.length + ', ')
if (connections.length > CONCURRENT || go) {
go = true
while(connections.length)
connections.shift()()
}
}).listen(9000);
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8000'.yellow);
util.puts('http server '.blue + 'started '.green.bold + 'on port '.blue + '9000 '.yellow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment