Node.js Versus Apache2: Bare Bones Test

N

I’ve written a few recent articles on Node.js, mostly to familiarize myself with the effort involved in creating basic applications with it.  I have yet to use it in production, mostly because I’m just not sure how ready I am to use it on a large project…

I have been quite curious with performance compared to the standard tools that I’ve used forever and ever.  In the following article, I’m going to do some basic comparisons between Node and Apache2 performance.

 To begin, I need to create two extremely simple websites, one for Node.js and one to be used for Apache.

Let’s begin with the Apache website; it will be a basic HTML page with Hello World outputted on screen:

[code]
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
[/code]

That’s nice and simple.  I proceeded to create a new virtual host and placed this index.html in its webroot.

Next, I will create a basic Node.js website.  In this example, I will use both Express and the Jade templating system.  This need to be installed if they are not already, so I will create a packages.json file:

[code]
{
“name”: “my-test-project”,
“version”: “0.0.1”,
“private”: true,
“dependencies”: {
“express”: “~3.0.0”,
“jade”: “>= 0.0.1”
}
}
[/code]

Now in a command prompt inside the folder where this file is present, I can run npm install and it will download and install both the Express and Jade packages.

Next up is a basic app.js file with one route for /:

[code]
var express = require(‘express’);
var app = express();
app.configure(function(){
app.set(‘view engine’, ‘jade’);
});

app.get(‘/’, function(req, res){
res.render(“index.jade”, {layout:false});
});

app.listen(8080);
[/code]

This creates a new Express server, defines the view engine as Jade and displays the index.jade file for the / route.  Here is a basic views/index.jade file:

[code]
!!! 5
html(lang=”en”)
head
title Hello World
body
h1 Hello World
[/code]

This will also output Hello World to screen just like the basic index.html file created earlier.  Now inside a command prompt I can start the application by typing node app.js.

It’s now time to compare Apples-to-Apples using my basic speed tester.

The results are astonishing!

First up I will run the speed tester on my Apache application.  In 10 seconds, the speed tester was able to load my Apache website 300 times.

And finally running the speed tester on my Node application, in 10 seconds the speed tester was able to load my Node application an incredible 6500+ times!

Summary

I’m incredibly astonished at the difference between the two results.  It’s important to note that I’m simply running this on my laptop running Windows 7.  There might be better or worse results running this on a production server running a different Operating System.  None-the-less, in this case the results speak for themselves.  Node out performed Apache by 21 requests to every 1 request!

About the author

By Jamie

My Books