title: http.get and http.request are both being extremely slow?
body: <p>When trying to load simple JSON APIs with the following code, I noticed the speeds were extremely slow:</p>
  
  <pre><code>function get(url, callback) {
      http.get(url, function(r) {
          var body = "";
          r.on('data', function(d) {
              body+=d;
          });
          r.on('end', function() {
              callback(body, false)
          });
      }).on('error', function (err) {
          callback(null, err.message.code)
      });
  }
  </code></pre>
  
  <p>Or posting with the following code:</p>
  
  <pre><code>function post(url, post_data, callback) {
  if (!post_data) post_data = "";
  var Proto = url.split("://")[0]+":";
  var Host = url.split("://")[1].split("/")[0];
  var Path = "/"+url.split("://")[1].replace("/", "#CHECK").split("#CHECK")[1];
  var req = http.request({
      host: Host,
      port: '80',
      path: Path,
      method: 'POST',
      headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Content-Length': Buffer.byteLength(post_data)
      }
  }, function(r) {
      var body = '';
      r.on('data', function(d) {
          body += d;
      });
      r.on('end', function() {
          callback(body);
      });     
  }).on('error', function (err) {
      callback(null, err.message.code)
  });
  req.write(querystring.stringify(post_data));
  req.end();
  }
  </code></pre>
  
  <p>Both take an extremely long time to go through, usually averaging me about 150-300 milliseconds per request on small files that would take me under 80ms to load in Google Chrome. To test, I used Google Chrome to benchmark and sent simple get and post requests, but it took 2 to 3 times longer to receive a response in node for each request than it did in Google Chrome. After doing some research, I found out it could possibly be due to Chrome, like most browsers, using the <code>Connection:"keep-alive"</code> header, but adding this in the headers seemed to have no impact. I'm already setting <code>http.globalAgent.maxSockets = 100000;</code> so I know that isn't the issue. How I can speed up my requests?</p>
  
  <p>Still have yet to find anything, if anyone knows if anything to speed things up please post a reply</p>