Archive

Posts Tagged ‘static page’

Linux Server – Task 7: Optimization and Varnish

Course
Linux palvelimena [Linux server] by Tero Karvinen at Haaga-Helia University of Applied Sciences

Task
Measure the speed difference between a local computer WordPress page and a similar static page with the ‘ab’ tool. Install Varnish (an HTTP acceleration tool) – measure the performance of a dynamic web page before and after the installation to gain data about the possible improvements.

Testing environment
OS: Xubuntu Linux 13.10 “Saucy Salamander” 32-bit (persistent live USB drive)
System: HP EliteBook 2570p Notebook PC

Preparing the installation environment
LAMP and WordPress have been installed.

Web server performance
I began testing the performance with Apache’s own benchmarking tool, which I started by entering the following in the terminal emulator (in the command -c means the number of clients, and -n the sent number of requests):

$ ab -c 200 -n 300 http://localhost/~xubuntu/jannevaris.com/|grep -P ‘Failed|#/sec|50%|100%|Length’

The results were as follows:
terminal1

The command prints an answer, where the size of the document, the number of failed requests, and the number of requests per second.

Next I ran the same command for one of my local WordPress page’s articles:

$ ab -c 200 -n 300 http://localhost/~xubuntu/jannevaris.com/?p=2/|grep -P ‘Failed|#/sec|50%|100%|Length’

The results were similar:

terminal

After this I tested a similar static page. First I created a new folder under the public_html folder named “statictest” with $ mkdir statictest. I created an index.html file in the folder with $ nano index.html, to which I copied the source code of my local WordPress’s front page. Then I saved the changes.

To finish the testing, I ran the same command for the static page:

$ ab -c 200 -n 300 http://localhost/~xubuntu/statictest/index.html/|grep -P ‘Failed|#/sec|50%|100%|Length’

The results showed that the page worked slightly faster when it was static:

terminal2

Installing Varnish
I installed Varnish with $ sudo apt-get install varnish. After the installation I had to set Varnish to listen to port 80, so I navigated to /etc/default/ with $ cd /etc/default/, and edited the necessary file with $ sudoedit varnish, so that the Alternative 2 part looked like this:

## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request.
#
DAEMON_OPTS=”-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m”

Then I saved the changes. After this I edited Apache’s port settings by navigating to /etc/apache2/ with $ cd /etc/apache2/, and editing ports.conf with $ sudoedit ports.conf. On the “Listen” line, I changed the port to 8080 and saved the changes.

After this I restarted Apache and Varnish with $ sudo service apache2 restart and $ sudo service varnish restart.

Next I compared the results before and after installing Varnish. I ran the following commands again:

$ ab -c 200 -n 300 http://localhost/~xubuntu/jannevaris.com/|grep -P ‘Failed|#/sec|50%|100%|Length’

$ ab -c 200 -n 300 http://localhost/~xubuntu/jannevaris.com/?p=2/|grep -P ‘Failed|#/sec|50%|100%|Length’

The results show that the requests now happen faster, from which we can determine that the pages have better performance after installing Varnish.

terminal3

terminal4

YSlow and Firebug analysis and offered improvements
Yahoo!’s page performance tool YSlow graded the local WordPress front page as A, with an overall performance score of 92. The only features not graded A were:

Grade E on Use a Content Delivery Network (CDN)

There are 5 static components that are not on CDN.

You can specify CDN hostnames in your preferences. See YSlow FAQ for details.

Grade F on Add Expires headers

There are 6 static components without a far-future expiration date.

Firebug’s Net panel came up with no improvement suggestions.

References
WordPress Codex (http://codex.wordpress.org/)
Karvinen, Tero: Lessons 2014-3-10, Linux palvelimena [Linux server] (http://terokarvinen.com/2013/aikataulu-%E2%80%93-linux-palvelimena-ict4tn003-11-ja-12-kevaalla-2014)

About
This document can be copied and edited according to the GNU General Public License (version 3 or newer). http://www.gnu.org/licenses/gpl.html
Based on a course by Tero Karvinen, http://www.iki.fi/karvinen