Simple Blog is a multi-part series. Check out The Index
In previous posts we designed a simple blog application using a variety of programming styles, patterns, and external libraries. Using’s Apache’s benchmark tool I’ve ran some tests to benchmark each different approach. Each benchmark hammers the respective application with 1000 pages requests across 10 concurrent sessions. The page we’ll call 1000 times is the List page which retrieves and displays all blog posts.
Here’s a list of the commands we’ll be running:
ab -c 10 -n 1000 http://baseurl/1-structured/index.php ab -c 10 -n 1000 http://baseurl/2-procedural/index.php ab -c 10 -n 1000 http://baseurl/3-objects/index.php ab -c 10 -n 1000 http://baseurl/4-mvc/index.php ab -c 10 -n 1000 http://baseurl/5-mysqli/index.php ab -c 10 -n 1000 http://baseurl/6-pdo/index.php ab -c 10 -n 1000 http://baseurl/7-smarty/index.php ab -c 10 -n 1000 http://baseurl/8-codeigniter/index.php
Here’s what the output looks like for the first test:
Document Length: 1396 bytes Concurrency Level: 10 Time taken for tests: 0.592 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 1619000 bytes HTML transferred: 1396000 bytes Requests per second: 1688.22 [#/sec] (mean) Time per request: 5.923 [ms] (mean) Time per request: 0.592 [ms] (mean, across all concurrent requests) Transfer rate: 2669.17 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.7 0 5 Processing: 1 5 4.6 5 90 Waiting: 0 5 4.4 4 78 Total: 1 6 4.6 5 90
The two values we’ll be comparing are time taken and requests per second.
1. Time taken for test shows the number of seconds taken to process 1,000 page request (lower is faster):
2. Number of page requests per second (higher is faster):
The applications developed using native PHP were 3x faster than those using the Smarty Template Engine and 10x faster than those using CodeIgniter. To look a little deeper, I ran another set of benchmarks with iostat running in the background. The I/O statistics captured showed that in all cases the file I/O incurred was minimal, which is most likely explained by database and filesystem caching. The key difference between the native PHP benchmarks and the CodeIgniter benchmark was a 57% increase in CPU utilization.
For more details about tuning CodeIgniter, check out this article by Elliot Haughhin titled Optimizing and Scaling your CodeIgniter Application where he tunes a simple CodeIgniter application using PHP’s memcache module, an open-source PHP accelerator named eAccelerator, and CodeIgniter’s own output caching.