title: Lots of parallel http requests in node.js
body: <p>I've created a node.js script, that scans network for available HTTP pages, so there is a lot of connections i want to run in parallel, but it seems that some of the requests wait for previous to complete.</p>
  
  <p>Following is the code fragment:</p>
  
  <pre><code>    var reply = { };
      reply.started = new Date().getTime();
      var req = http.request(options, function(res) {
          reply.status = res.statusCode;
          reply.rawHeaders = res.headers;
          reply.headers = JSON.stringify(res.headers);
          reply.body = '';
          res.setEncoding('utf8');
          res.on('data', function (chunk) {
              reply.body += chunk;
          });
          res.on('end', function () {
              reply.finished = new Date().getTime();
              reply.time = reply.finished - reply.started;
              callback(reply);
          });
      });
      req.on('error', function(e) {
          if(e.message == 'socket hang up') {
              return;
          }
          errCallback(e.message);
      });
      req.end();
  </code></pre>
  
  <p>This code performs only 10-20 requests per second, but i need 500-1k requests performance. Every queued request is made to a different HTTP server.</p>
  
  <p>I've tried to do something like that, but it didn't help:</p>
  
  <pre><code>    http.globalAgent.maxSockets = 500;
  </code></pre>