I'm evaluating performance of Node.js (.5.1-pre) versus Apache (2.2.17) for a simple scenario - serving a text file.

Here's the code I personally use for node server:

var http = require('http')

  , fs = require('fs')

fs.readFile('/var/world wide web/README.txt',

    function(err, data) )

            res.finish(data)

        ).listen(8080, '127...1')

    

)

For Apache I'm simply using whatever default configuration which matches with Ubuntu 11.04

When running Apache Bench using the following parameters against Apache

ab -n10000 -c100 http://127...1/README.txt

I recieve the next runtimes:

Time taken for tests:   1.083 seconds

Complete demands:      10000

Unsuccessful demands:

Write errors:

Total moved:      27630000 bytes

HTML moved:       24830000 bytes

Demands per second:    9229.38 [#/sec] (mean)

Time per request:       10.835 [ms] (mean)

Time per request:       .108 [ms] (mean, across all concurrent demands)

Transfer rate:          24903.11 [Kbytes/sec] received

Connection Occasions (ms)

              min  mean[+/-sd] median   max

Connect:               .8             9

Processing:     5   10   2.     10      23

Waiting:        4   10   1.9     10      21

Total:          6   11   2.1     10      23

Area of the demands offered inside a certain time (ms)

  50%     10

  66%     11

  75%     11

  80%     11

  90%     14

  95%     15

  98%     18

  99%     19

 100%     23 (longest request)

When running Apache bench against node instance, fundamental essentials runtimes:

Time taken for tests:   1.712 seconds

Complete demands:      10000

Unsuccessful demands:

Write errors:

Total moved:      25470000 bytes

HTML moved:       24830000 bytes

Demands per second:    5840.83 [#/sec] (mean)

Time per request:       17.121 [ms] (mean)

Time per request:       .171 [ms] (mean, across all concurrent demands)

Transfer rate:          14527.94 [Kbytes/sec] received

Connection Occasions (ms)

              min  mean[+/-sd] median   max

Connect:               .9             8

Processing:        17   8.8     16      53

Waiting:           17   8.6     16      48

Total:          1   17   8.7     17      53

Area of the demands offered inside a certain time (ms)

  50%     17

  66%     21

  75%     23

  80%     25

  90%     28

  95%     31

  98%     35

  99%     38

 100%     53 (longest request)

That is clearly reduced than Apache. This is particularly surprising should you think about it that Apache does lots of other things, like logging etc.

Am I doing the work wrong? Or perhaps is Node.js really reduced within this scenario?

Edit 1: I actually do observe that node's concurrency is much better - when growing numerous synchronised request to 1000, Apache begins shedding couple of of these, while node works fine without any connections dropped.

Within this scenario Apache is most likely doing sendfile which lead to kernel delivering chunk of memory data (cached by fs driver) straight to socket. Within the situation of node there's some overhead in copying data in userspace between v8, libeio and kernel (see this great article on using sendfile in node)

You will find plenty possible scenarious where node will outshine Apache, like 'send stream of information with constant slow speed to as numerous tcp connections as possible'