http - Making requests with node.js in a loop performance -


i'm trying benchmark node.js express app following using request library:

var request = require('request');  var totalrequests = 100000;  for(var = 0; < totalrequests; i++) {     (function(i) {         request('http://localhost:3000/', function(error, response, body) {             console.info('request ' + (i + 1));         });     })(i); } 

when run it, don't see console.info() request callback requests on 40 seconds, start. should'nt see requests firing right away?

40 seconds may amount of time takes prepare 100,000 requests. since you're looping synchronously, callbacks can't called until after of requests have been initiated.

i suggest library async if intended make or of requests in series rather in parallel.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -