-
-
Save robertlmullen74/2116100 to your computer and use it in GitHub Desktop.
Simple ab style load generator
This file contains hidden or 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
// requires request, measured, optimist and microtime npm modules | |
var util = require('util') | |
, request = require('request') | |
, microtime = require('microtime') | |
, measured = require('measured') | |
, collection = new measured.Collection('http') | |
, argv = require('optimist').usage('node load.js -c [concurrent] -n [total] url').argv; | |
var c = argv.c || 1 | |
, n = argv.n || 1, uri = argv._[0] | |
, running = 0, ran=0, finished=0 | |
, timer = collection.timer(uri); | |
var statusInterval = setInterval(function() { | |
console.log([running, ran, finished, (Math.round(100*finished/n)) + "%"].join(', ')); | |
}, 2000); | |
(function run(uri) { | |
running++; ran++; | |
if( running < c ) run(uri); | |
var start = microtime.now(); | |
request(uri, function (error, response, body) { | |
running--; finished++; | |
timer.update(microtime.now() - start); | |
if(ran !== n) run(uri); | |
if(finished === n) { | |
console.log(util.inspect(collection.toJSON(), false, 10)); | |
clearInterval(statusInterval); | |
process.exit(0); | |
} | |
}); | |
}(uri)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment