3 times speed increase with static pages

3 times speed increase with static pages

Posted by

Internet was born from static pages. People were creating websites with emacs and vi. With the increased popularity of scripting languages and open-source databases like MySQL and Postgresql, more and more developers started to use these advanced tools.

CMS – Content Management Systems systems were built. They made our lives much easier. Instead of altering file contents with the text editor, the user can simply go to the website admin panel and change page from there.

The speed of loading page generated in PHP with MySQL is much slower than a static page. In addition, on every page request, CMS can generate tens or even hundreds of database requests.

With the advances of new web technologies like Jquery and HTML5, we have a chance to get back to the roots. We can create static websites that behave the same as dynamic ones.

I would like to show you some benchmarks.

In my test, I will fetch two small test pages. One with static content and another one generated with PHP and MySQL.

Contents of test.html file:

<html>
<head>
<title>hello world</title>
</head>
<body>
<h2>Hello world!</h2>
</body>
</html>

Contents of test.php file:

<html>
<head>
<title>hello world</title>
</head>
<body>
<?php
$handler =  mysql_connect('127.0.0.1', 'user', 'password');
$result = mysql_query("SELECT 'Hello World!'");
$row = mysql_fetch_row($result);
print "<h2>$row[0]</h2>\n";
?>
</body>
</html>

In my test, I used the “ab” command to test web application speed. It stands for Apache Bench – a small application to perform a quick test for website speed.

To test static page speed I use the following command:

ab -c 100 -n 10000 http://website.com/test.html

To test dynamic page speed I use the following command:

ab -c 100 -n 10000 http://website.com/test.php

In this test, I got the following result.

Static pages are at least 3 times faster than dynamic pages generated with PHP and MySQL.

In my production server, at average, ab was able to fetch almost 15k requests per second for test.html static page and 5k requests per second for the test.php dynamic page.

Feel free to leave your benchmark results here.