title: NodeJS benchmark
body: <p>I've made benchmark, to compare what is faster NodeJS or Apache + PHP?</p>
  
  <p>When I had tested 'Hello world' application Node was faster, but when I tried to use http.get function It was completely different story.</p>
  
  <p>Why NodeJS is becoming so slow? Is it deal in http.get ? or what?</p>
  
  <p><strong>Test environment</strong></p>
  
  <pre>
  CPU             Intel(R) Core(TM) i5 CPU M 430 @ 2.27GHz
  Memory          2927MiB
  OS              Ubuntu 12.04 LTS
  Test Platform   Apache Bench
  NodeJS          v0.8.2
  Apache          Apache/2.2.22
  PHP             PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli)
  </pre>
  
  <hr>
  
  <p><strong>1. Hello world application:</strong></p>
  
  <p>NodeJS code:</p>
  
  <pre><code>var http        = require('http');
  
  http.createServer(function(req, res) {
  
      res.writeHead(200, {"Content-Type": "text/html"});
  
      res.end('hello world');    
  
  }).listen(8888);
  </code></pre>
  
  <p>PHP code:</p>
  
  <pre><code>&lt;?php
  
      echo "hello world"
  
  ?&gt;
  </code></pre>
  
  <p>Results:</p>
  
  <h2>Heading</h2>
  
  <p><strong>ab -n 10000 -c 10 hostname</strong>                                 .<br>
  10.000 requests, 10 concurrent (time in seconds)</p>
  
  <pre>
  NodeJS      1.337   1.361   1.313   1.312   1.329
  Apache+PHP  3.923   3.910   3.917   3.926   3.921
  </pre>
  
  <p><strong>ab -n 10000 -c 100 hostname</strong>        </p>
  
  <p>10.000 requests, 100 concurrent (time in seconds)</p>
  
  <pre>   
  NodeJS      1.326   1.369   1.330   1.333   1.459
  Apache+PHP  3.933   3.917   3.940   3.908   3.913
  </pre>
  
  <p><strong>ab -n 100000 -c 300 hostname</strong>                      </p>
  
  <p>100.000 requests, 300 concurrent (time in seconds)</p>
  
  <pre>
  NodeJS      13.560  13.647  13.784  13.807  14.082
  Apache+PHP  44.061  41.516  41.523  41.466  41.465
  </pre>
  
  <hr>
  
  <p><strong>2.  Pull feeds application:</strong></p>
  
  <p>NodeJS code:</p>
  
  <pre><code>var http = require('http');
  
  
  var options1 = {
            host: 'www.google.com',
            port: 80,
            path: '/',
            method: 'GET'
          };
  
  http.createServer(function (req, res) {
  
  
      http.get(options1, function(response) {
  
          response.on('data', function (chunk) {
  
          });
  
          response.on('end', function (chunk) {
              res.writeHead(200, {'Content-Type': 'text/html'});
              res.end('ok');
          });
  
      });
  
  
  }).listen(8888);
  </code></pre>
  
  <p>PHP code:</p>
  
  <pre><code>&lt;?php
      file_get_contents('http://www.google.com');
  
      echo 'ok';
  ?&gt;
  </code></pre>
  
  <p>Results:</p>
  
  <p>*<em>ab -n 100 -c 10 hostname *</em>                         </p>
  
  <p>100 requests, 10 concurrent (time in seconds)</p>
  
  <pre>
  NodeJS       8.034  8.492   8.619   7.464   7.950
  Apache+PHP  18.648  16.699  19.428  17.903  18.297
  </pre>
  
  <p>*<em>ab -n 1000 -c 10 hostname *</em>     </p>
  
  <p>1000 requests, 10 concurrent (time in seconds)</p>
  
  <pre>
  NodeJS       68.361 74.705  78.473  74.138  66.779
  Apache+PHP  150.568 159.024 161.179 160.819 157.605
  </pre>
  
  <p>*<em>ab -n 10000 -c 100 hostname *</em><br>
  10.000 requests, 100 concurrent (time in seconds)</p>
  
  <pre>
  NodeJS     1666.988 739.370         
  Apache+PHP  310.062 244.485         
  </pre>
  
  <p>*<em>ab -n 10000 -c 50 hostname *</em><br>
  10.000 requests, 50 concurrent (time in seconds)</p>
  
  <pre>
  NodeJS      256.096 260.625         
  Apache+PHP  149.422 154.422         
  </pre>