Note that there are some explanatory texts on larger screens.

plurals
  1. PONode.js slower than Apache
    text
    copied!<p>I am comparing performance of Node.js (0.5.1-pre) vs Apache (2.2.17) for a very simple scenario - serving a text file.</p> <p>Here's the code I use for node server:</p> <pre><code>var http = require('http') , fs = require('fs') fs.readFile('/var/www/README.txt', function(err, data) { http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}) res.end(data) }).listen(8080, '127.0.0.1') } ) </code></pre> <p>For Apache I am just using whatever default configuration which goes with Ubuntu 11.04</p> <p>When running Apache Bench with the following parameters against <strong>Apache</strong></p> <pre><code>ab -n10000 -c100 http://127.0.0.1/README.txt </code></pre> <p>I get the following runtimes:</p> <pre><code>Time taken for tests: 1.083 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 27630000 bytes HTML transferred: 24830000 bytes Requests per second: 9229.38 [#/sec] (mean) Time per request: 10.835 [ms] (mean) Time per request: 0.108 [ms] (mean, across all concurrent requests) Transfer rate: 24903.11 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.8 0 9 Processing: 5 10 2.0 10 23 Waiting: 4 10 1.9 10 21 Total: 6 11 2.1 10 23 Percentage of the requests served within a certain time (ms) 50% 10 66% 11 75% 11 80% 11 90% 14 95% 15 98% 18 99% 19 100% 23 (longest request) </code></pre> <p>When running Apache bench against <strong>node</strong> instance, these are the runtimes:</p> <pre><code>Time taken for tests: 1.712 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Total transferred: 25470000 bytes HTML transferred: 24830000 bytes Requests per second: 5840.83 [#/sec] (mean) Time per request: 17.121 [ms] (mean) Time per request: 0.171 [ms] (mean, across all concurrent requests) Transfer rate: 14527.94 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.9 0 8 Processing: 0 17 8.8 16 53 Waiting: 0 17 8.6 16 48 Total: 1 17 8.7 17 53 Percentage of the requests served within a certain time (ms) 50% 17 66% 21 75% 23 80% 25 90% 28 95% 31 98% 35 99% 38 100% 53 (longest request) </code></pre> <p>Which is clearly slower than Apache. This is especially surprising if you consider the fact that Apache is doing a lot of other stuff, like logging etc.</p> <p>Am I doing it wrong? Or is Node.js really slower in this scenario?</p> <p><strong>Edit 1</strong>: I do notice that node's concurrency is better - when increasing a number of simultaneous request to 1000, Apache starts dropping few of them, while node works fine with no connections dropped.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload