Optimize WordPress for speed

WordPress is a popular platform for blogs and I have found there are some “simple” optimizations that have made a huge difference in speed. Although this was written for WordPress, it boosts the speed of all PHP driven web applications, such as Moodle, although the performance enhancement on Moodle was not as brisk.

While there are many ways to optimize Apache and Mysql, this how-to focuses primarily on optimization of PHP (I will leave Apache/Lighttpd and Mysql performance to my readers for now).

For the impatient : Here are the results

Performance testing

Benchmarking was performed over the LAN using ab on paultag’s blog (running in an OpenVZ container). Thank you to paultag for allowing me access to his VPS.

Hardware:

CPU: Intel(R) Xeon(TM) CPU 3.00GHz
Web server: Apache 2.2.11 or Lighttpd 1.4.19
Wordpress : 2.7.1

Baseline WordPress performance

This was the baseline performance of WordPress out of the box (these numbers speak for themselves). If you performance test your WordPress install your numbers will likely be very similar.

ab -n 100 -c 10 http://blog.paultags.com/
This is ApacheBench, Version 2.3 >$Revision: 655654 $<
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking blog.paultags.com (be patient).....done


Server Software: Apache/2.2.11
Server Hostname: blog.paultags.com
Server Port: 80


Document Path: /
Document Length: 9547 bytes


Concurrency Level: 10
Time taken for tests: 7.568 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 271800 bytes
HTML transferred: 224800 bytes
Requests per second: 13.21 [#/sec] (mean)
Time per request: 756.794 [ms] (mean)
Time per request: 75.679 [ms] (mean, across all concurrent requests)
Transfer rate: 35.07 [Kbytes/sec] received


Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 241 495 545.3 360 3635
Waiting: 241 495 545.3 360 3634
Total: 241 496 545.3 360 3635


Percentage of the requests served within a certain time (ms)
50% 360
66% 413
75% 452
80% 517
90% 653
95% 945
98% 3429
99% 3635
100% 3635

Optimization

1. Optimize Mysql. While there are many ways to optimize Apache, Lighttpd, and Mysql, there is one small tweak to Mysql worth mentioning.

Using any editor, open /etc/mysql/my.cnf and disable InnoDB. This is an easy edit, simply remove the # from the line :

#skip-innodb

skip-innodb

This significantly reduces the ram used by Mysql (read the comments in the config file, just above the line we edited).

2. Optimize PHP with a “PHP Accelerator” . Here I use APC as I found it performs a bit better then xcache or eAccelerator (unpublished data).

Alternative PHP Cache (APC) is a free, open source framework that optimizes PHP intermediate code and caches data and compiled code from the PHP bytecode compiler in shared memory.

sudo apt-get install php-apc

3. Increase the PHP memory limit. Open your php.ini

Apache : /etc/php5/apache2/php.ini
Lighttpd: /etc/php5/cgi/php.ini

change

memory_limit = 16M

to (you may go to 128 M if you wish)

memory_limit = 64M

4. Install memcache

memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

sudo apt-get install php5-memcache memcached

5. Install WordPress Cache (WP-Supercache is more complex and did not perform any better). This last step does not add as much as the PHP Acceleration or memcache.

WP Cache

After installation, activate the plugin and make sure it is enabled in your wordpress admin panel.

6. Restart your web server :

Apache :

sudo /etc/init.d/apache2 restart

Lighttpd :

sudo /etc/init.d/lighttpd restart

With these configuration changes you will use less ram (due the the mMsql edit). APC and memcache use approximately 25 Mb of ram.

Results

OMG THAT’S HUGE


ab -n 100 -c 10 http://blog.paultags.com/
This is ApacheBench, Version 2.3 >$Revision: 655654 $<
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking blog.paultags.com (be patient).....done


Server Software: Apache/2.2.11
Server Hostname: blog.paultags.com
Server Port: 80


Document Path: /
Document Length: 9547 bytes


Concurrency Level: 10
Time taken for tests: 0.051 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 998949 bytes
HTML transferred: 962892 bytes
Requests per second: 1942.31 [#/sec] (mean)
Time per request: 5.149 [ms] (mean)
Time per request: 0.515 [ms] (mean, across all concurrent requests)
Transfer rate: 18947.97 [Kbytes/sec] received


Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 3 4 0.7 4 7
Waiting: 2 4 0.6 4 6
Total: 4 5 0.7 5 8


Percentage of the requests served within a certain time (ms)
50% 5
66% 5
75% 5
80% 5
90% 6
95% 6
98% 8
99% 8

This entry was posted in Linux. Bookmark the permalink.

22 Responses to Optimize WordPress for speed

  1. Pingback: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed | MyClickSense.com

  2. Pingback: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed

  3. Pingback: Twitted by Dananjaya86

  4. Pingback: theBside » Blog Archive

  5. Pingback: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed | eWebsite.biz

  6. Kirrus says:

    I know of a wordpress-powered blog, so far this month just under 400,000 Uniques, just under 35 million hits (35,000,000), which without supercache would be a messy puddle.

    I’ve tried just using wp-cache, and it just doesn’t quite cut it.. I find that slowly (over 3-4 minutes), load climbs, till the server starts backing up. Once it’s backing up, that’s it, you’ve had it, the server is useless, with loads at 50-100+ … ;)

    We’re using eAccelerator, so I might try shifting it to apc, next time I need to do maintainance.

    (Right now, the server, with 2 cores, is at a load of around 0.25 :))

  7. Pingback: Wordpress UK » Shadows of epiphany » Blog Archive » Optimize bWordpress/b for speed

  8. Pingback: Web design Speed | Web Development | Web Site Design | SEO | Tips » Shadows of epiphany » Blog Archive » Optimize Wordpress for speed

  9. bodhi.zazen says:

    Kirrus: Thank you for your comments and wisdom.

    I agree every server is different.

    You may easily use supercache with PHP accelerators and memcache.

    Good luck with APC. I benchmarked the PHP Accelerators on my server (using lighttpd) and posted my results here :

    http://blog.bodhizazen.net/linux/lighttpd-php-acceleration-benchmarks/

    In actual use I was not as happy with xcache (I started getting 505 errors) and so ended up with apc. Such is the problem with making decisions only on the basis of benchmarks (and not watching your server performance).

  10. Pingback: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed | thewordpresssecrets

  11. Pingback: ZedTuX On R00t » Optimisation d’un serveur web

  12. mark says:

    Hi.Very nice website.I will come back again.

  13. paul oconnor says:

    great website and informations.thanx

  14. Kirrus says:

    Well, our experiment with APC went well. Both the debian-backported package, or the pecl installed version failed every couple of hours, serving just a white, blank, page until the apache was restarted.

    Returned to eaccelerator… running without it isn’t an option :(

  15. bodhi.zazen says:

    Sorry you had a bad experience with APC. I have been running APC on lighttpd without any issues.

    Yet another example of why one can not make decisions based on benchmarks alone ;)

    I would be curious to know if you ever identified the cause of your problems with apc ?

  16. Kirrus says:

    It was segfaulting apache servers. Not sure why, didn’t really have the time for a lot of really detailed analysis ;)

  17. blueworld says:

    Great story. thanks, keep it coming.

  18. paultag says:

    As I’ve said before, amazing work here. I have seen an incredible increase in performance. IMHO, the results are able to speak for them self, not to mention a huge benefit regarding CPU and RAM usage. Yeah, it may cache a lot more ( == more RAM usage ) but in the long run, preventing needless execution of code will save a lot more RAM. This really allowed WordPress to shine on my install.

    Thanks again bodhi! Outstanding work as usual.

  19. Naveed says:

    test test test awesome google good test test

  20. bodhi.zazen says:

    LOL Naveed , glad you liked it. Your post reminds me, need caffeine …

  21. Pingback: Best Open CMS: WordPress vs Joomla vs Drupal « Keep an Open Eye Eye, Sir

  22. Pingback: Optimizing MySQL for small VPS - Admins Goodies

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>