Created
July 6, 2015 15:04
-
-
Save Kosta-Github/d850ac2a52b75243204d to your computer and use it in GitHub Desktop.
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 debug = require('debug')('stress-test'); | |
var request = require('request'); | |
request.defaults({ timeout: 500 }); | |
var haproxy = undefined; | |
var do_request = function(id) { | |
var start_time = process.hrtime(); | |
request.get('http://echo.service.my_company.com', function(err, res, body) { | |
var diff_time = process.hrtime(start_time); | |
var duration = (diff_time[0] * 1000 + diff_time[1] / 10000000) | 0; | |
if(err) { | |
debug('%s: request error: %s, duration: %s', id, err, duration); | |
} else if(res.statusCode != 200) { | |
debug('%s: status: %s, duration: %s', id, res.statusCode, duration); | |
} else { | |
var data = JSON.parse(body); | |
var h = data.remoteAddress; | |
{ // if((duration >= 100) || (haproxy !== h)) { | |
haproxy = h; | |
debug('%s: remote address: %s, service host: %s, duration: %s', id, h, res.headers['x-bla-host'], duration); | |
} | |
} | |
// tail recursion | |
setTimeout(function() { do_request(id) }, Math.random() * 10); | |
}); | |
}; | |
for(var i = 0; i < 10; ++i) { | |
do_request(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment