Created
August 17, 2011 22:36
-
-
Save markdaws/1152822 to your computer and use it in GitHub Desktop.
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
var 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 numberOfRequests = 1000; | |
var completedCount = 0; | |
var startTime = (new Date()).getTime(); | |
function callAPI(id) { | |
doGet(id + ': GET1', | |
http, | |
host, | |
80, | |
apiPath + '&rand=' + (count++), | |
function(err, response) { | |
++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; | |
} | |
setTimeout(function() { | |
callAPI(id + 1); | |
}, 1000); | |
}); | |
} | |
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(); | |
} | |
callAPI(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment