Benchmarking Node.js - basic performance tests against Apache + PHP

Original contemporary horse racing painting by Robert Joyner

Several days ago I have done few very basic performance tests to see how node.js server behaves compared to Apache when serving very simple pages.

All tests were executed on dual-core Intel T4200 2 GHZ machine with 4 GB RAM running Ubuntu 10.04 Lucid (with X).

For comparison I have used node.js 0.1.103 on one side, and Apache 2.2.14 with prefork MPM and PHP 5.2.10 on the other, hitting them with ApacheBench 2.3 and total of 100,000 request with 1,000 concurrent requests during first test:

ab -r -n 100000 -c 1000 <url>

and then with total of 1,000,000 requests and 20,000 concurrent requests during the second one:

ab -r -n 1000000 -c 20000 <url>

Basic "Hello World" node.js server used for testing:

and equally basic "Hello World" PHP file for Apache:

Results

1) Total request: 100,000; concurrency level: 1,000

node.js results:

Apache results:

To illustrate CPU and memory load changes I have measured them during tests using dstat (first for node.js, and then Apache right afterwards), with following results:

CPU Usage: node.js vs Apache/PHP in ApacheBench test - 100k requests, 1k concurrent requests

CPU Usage: node.js vs Apache/PHP in ApacheBench test - 100k requests, 1k concurrent requests

Memory Usage: node.js vs Apache/PHP in ApacheBench test - 100k requests, 1k concurrent requests

Memory Usage: node.js vs Apache/PHP in ApacheBench test - 100k requests, 1k concurrent requests

2) Total requests: 1,000,000; concurrency level: 20,000

noe.js results:

Apache results:

Again, CPU and memory usage comparison:

CPU Usage: node.js vs Apache/PHP in ApacheBench test - 1M requests, 20k concurrent requests

CPU Usage: node.js vs Apache/PHP in ApacheBench test - 1M requests, 20k concurrent requests

Memory Usage: node.js vs Apache/PHP in ApacheBench test - 1M requests, 20k concurrent requests

Memory Usage: node.js vs Apache/PHP in ApacheBench test - 1M requests, 20k concurrent requests

Conclusions

As the above tests show, node is fast. Really fast. Much faster than Apache - many more requests per second, higher transfer rate with much smaller number of failed requests at the same time. Really shining.

Obviously it is more hungry for system's CPU and memory, but this should not be surprising considering its performance.

What needs to be kept in mind though is that everything really depends on what you want to use Node for. As already said in many places, Node is not something that should replace Apache everywhere.

When considering using Node for a new project (or rewriting an old one) absolutely first thing to do is to make sure that Node really is a good fit for it. Also, depending on project's planned features, used libraries, connections with other systems and/or databases, Node performance could be completely different and not that exciting anymore.

The point is - all those tests above are only the very first point of reference - but to make sure that Node really meets your own specific requirements, you need to test your own system yourself.