Created
August 2, 2011 04:15
-
-
Save dominictarr/1119591 to your computer and use it in GitHub Desktop.
script to check level of concurrency through proxy
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 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