Created
August 17, 2011 23:00
-
-
Save markdaws/1152865 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
ar http = require('http'); | |
var util = require('util'); | |
var count = (new Date()).getTime(); | |
var apiPath = 'services/rest/?method=flickr.photos.getInfo&api_key=52102ae42eabc584b4f587b5f7aa5797&photo_id=6053145786+-+013&format=rest'; | |
var host = 'api.flickr.com'; | |
var agent = http.getAgent(host, 80); | |
agent.maxSockets = 50; | |
console.log(util.inspect(agent)); | |
var numberOfRequests = 250; | |
var completedCount = 0; | |
var startTime = (new Date()).getTime(); | |
function callAPI(id) { | |
doGet(id + ': GET1', | |
http, | |
host, | |
80, | |
apiPath + '&rand=' + (count++), | |
function(err, response) { | |
if(err) { | |
console.log('ERROR:' + err); | |
return; | |
} | |
++completedCount; | |
console.log(id + ' completed (' + completedCount + ' of ' + numberOfRequests + ')'); | |
if(numberOfRequests === completedCount) { | |
var endTime = (new Date()).getTime(); | |
console.log('num req:' + numberOfRequests + | |
', time:' + (endTime-startTime)/1000 + '(s)'); | |
return; | |
} | |
}); | |
} | |
function doGet(id, protocol, host, port, path, callback) { | |
var options = { | |
host: host, | |
port: port, | |
path: path, | |
method: 'GET' | |
}; | |
var req = protocol.request(options, function(res) { | |
var response = ''; | |
res.on('data', function (chunk) { | |
response += chunk; | |
}); | |
res.on('end', function () { | |
callback(null, response); | |
}); | |
res.on('error', function (e) { | |
callback(e, null); | |
}); | |
}); | |
req.on('error', function(e) { | |
callback(e, null); | |
}); | |
req.end(); | |
} | |
for(var i=0; i<numberOfRequests; ++i) { | |
callAPI(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment