Node.js Versus Apache2: Bare Bones Test

Published on Dec 3, 2012 by Jamie Munro

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:


<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>


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:


{
"name": "my-test-project",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "~3.0.0",
"jade": ">= 0.0.1"
}
}


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 /:


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);


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:


!!! 5
html(lang="en")
head
title Hello World
body
h1 Hello World


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!

Tags: Optimization | speed comparison | Theory | JavaScript | node | apache

Related Posts

blog comments powered by Disqus