title: Nodejs Reverse Proxy Performance
body: <p>I am investigating the possibility of using Node to act as a reverse proxy.  One of the primary goals of my project is for it to be VERY high performance.  So I've setup a node server to proxy requests to the target node server that will respond with 'hello world' no matter the request.</p>
  
  <p>Using Apache Bench I've done some comparison on the number of requests processed per second.  The proxy, target and caller are each on separate M1 Large instances in AWS.  My results are frustrating and confusing.</p>
  
  <p>Direct from caller to Target:</p>
  
  <pre><code>ab -c 100 -n 10000 http://target-instance/
  </code></pre>
  
  <p>= ~2600 requests/second</p>
  
  <p>From caller through proxy to target</p>
  
  <pre><code>ab -c 100 -n 10000 http://proxy-instance/
  </code></pre>
  
  <p>= ~1100 requests/second</p>
  
  <p>Using lighttpd I was able to get ~3500 requests/second on proxy and target</p>
  
  <p>I'm disappointed that the proxy server is less performant than the target server.  When comparing other products like lighttpd I've seen the proxy achieve comparable results to the target so I'm confused about when Node (supposed to be lightening fast) is not achieving the same.</p>
  
  <p>Here's my proxy code in Node v0.5.9: Am I missing something?</p>
  
  <pre><code>var server =
  http.createServer(function(req, res){
      var opts = { host: 'target-instance',
                   port: 80,
                   path: '/',
                   method: 'GET'};
      var proxyRequest = http.get(opts, function(response){
              response.on('data', function(chunk){
                      res.write(chunk);
              });
              response.on('end', function(){
                      res.end()
              });
      });
  });
  server.listen(80);
  </code></pre>