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.
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
Posted in Linux
[...] Visit link: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed [...]
Pingback by Shadows of epiphany » Blog Archive » Optimize Wordpress for speed | MyClickSense.com — May 27, 2009 @ 5:50 pm
[...] Continued here: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed [...]
Pingback by Shadows of epiphany » Blog Archive » Optimize Wordpress for speed — May 27, 2009 @ 9:14 pm
[...] This post was Twitted by Dananjaya86 – Real-url.org [...]
Pingback by Twitted by Dananjaya86 — May 27, 2009 @ 10:27 pm
[...] Optimize Wordpress for speed [...]
Pingback by theBside » Blog Archive — May 27, 2009 @ 11:00 pm
[...] Read the original here: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed [...]
Pingback by Shadows of epiphany » Blog Archive » Optimize Wordpress for speed | eWebsite.biz — May 28, 2009 @ 1:29 am
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
)
Comment by Kirrus — May 28, 2009 @ 5:33 am
[...] the original here: Shadows of epiphany » Blog Archive » Optimize bWordpress/b for speed This entry was posted on Wednesday, May 27th, 2009 and is filed under Wordpress News. You can [...]
Pingback by Wordpress UK » Shadows of epiphany » Blog Archive » Optimize bWordpress/b for speed — May 28, 2009 @ 6:03 am
[...] here to read the rest: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed Share and [...]
Pingback by Web design Speed | Web Development | Web Site Design | SEO | Tips » Shadows of epiphany » Blog Archive » Optimize Wordpress for speed — May 28, 2009 @ 6:37 am
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).
Comment by bodhi.zazen — May 28, 2009 @ 9:23 am
[...] Original post: Shadows of epiphany » Blog Archive » Optimize Wordpress for speed [...]
Pingback by Shadows of epiphany » Blog Archive » Optimize Wordpress for speed | thewordpresssecrets — May 28, 2009 @ 3:47 pm
[...] Source: http://blog.bodhizazen.net/linux/optimize-wordpress-for-speed/ [...]
Pingback by ZedTuX On R00t » Optimisation d’un serveur web — May 29, 2009 @ 12:07 am
Hi.Very nice website.I will come back again.
Comment by mark — June 28, 2009 @ 5:05 am
great website and informations.thanx
Comment by paul oconnor — June 28, 2009 @ 5:41 am
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
Comment by Kirrus — June 29, 2009 @ 8:17 am
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 ?
Comment by bodhi.zazen — June 29, 2009 @ 10:58 am
It was segfaulting apache servers. Not sure why, didn’t really have the time for a lot of really detailed analysis
Comment by Kirrus — June 30, 2009 @ 4:44 am
Great story. thanks, keep it coming.
Comment by blueworld — July 3, 2009 @ 6:58 am
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.
Comment by paultag — July 19, 2009 @ 12:57 pm
test test test awesome google good test test
Comment by Naveed — January 28, 2010 @ 6:19 am
LOL Naveed , glad you liked it. Your post reminds me, need caffeine …
Comment by bodhi.zazen — January 28, 2010 @ 9:38 am