[…] DiggProof your Wordpress A close look at optimizing and tweaking your MySql database for Wordpress and other tips and plugins to make your Wordpress blog faster than it already is. Even though Wordpress is fast in its own right, this article is geared for high traffic blogs and especially those that run Wordpress on smaller Virtual Private Servers. […]
DiggProof your Wordpress
Note: This post is over a year and a half old. You may want to check later in this blog to see if there is new information.
The following links are auto-generated but may help you locate newer content:
I know, it’s a ballsy headline, but I’m tired of hearing all of the script kiddies on Digg scoff at Wordpress, blaming it for sites crashing from the “Digg Effect.” Drupal, Movable Type and others all have similar problems, but there’s a lot of people saying you should never Digg a Wordpress site because it will always crash. Wordpress needs a little tweaking, but for the most part, it’s the server configuration that is to blame. Maybe the new release of Wordpress will improve on some of the caching issues, but from what I can tell, it mostly improves on aspects of Wordpress that I don’t use anyway (draft saving, image handling, modules, etc.).
So, in my usual fashion, I’m doing my best to provide what I’m hoping will be useful information for anyone running Wordpress on a server they have some control over. The information in this post should help anybody running any kind of website on any LAMP server. It just happens to contain some Wordpress specific information as a bonus.
So go ahead, Digg this post to the front page. If my server crashes, I’ll bury my head in the sand and live in infamy while you travel on to the next most popular site on Digg. But I believe that the changes I’ve outlined here have significantly improved my chances of withstanding some serious traffic influxes.
Obviously, the easiest thing you can do is add RAM and a faster CPU to your server, given that it’s even an option. However, you can make any half-decent system run a lot better with a few tweaks.
Apache
There’s an excellent guide to Apache server optimization at HowToForge. You’ll need access to your httpd.conf file and the ability to restart your apache server (often ‘apachectl graceful’) to put the guide to use. Also keep in mind when reading it that the section on .htaccess files requires special attention if you’re using software that utilizes friendly URLs (and most does these days). If you don’t set AllowOverride to All, make sure that you include the directories that require .htaccess use in the directive.
MySQL Query Cache
One of the biggest and quickest performance gains I found was enabling MySQL’s Qcache. You can see the current state of your cache by typing “SHOW STATUS LIKE ‘Qcache%’;” (without the double quotes) at your mysql prompt. Both the query_cache_type and the query_cache_size need to be non-zero for the cache to be enabled. To enable your Query Cache, add to your /etc/my.cnf:
query_cache_type = 1 query_cache_size = 20M query_cache_limit = 2M
The size of the cache is determined by your setup, and the limit is determined by your caching needs. Here’s a passage from the mySQL newsletter:
Setting proper query_cache_size is the most complex task. It sets the amount of memory used for the query cache. One should find the right balance between the benefit you get from query cache and that non-cached queries slow down a bit, basicly due to less amount of memory available for other caches and buffers. Only benchmarking can point out the exactly best balance, but there are some guidelines, how to set this variable. Basic idea is that the more benefit query cache potentially gives you, the more memory it might be worth to allocate for it. Qcache_inserts will show you how many queries are added to query cache while qcache_hits will show you how many query results are taken directly from the query cache instead of executing them. You should compare qcache_hits value to total number of your select queries to see what is your current hit rate. You may increase or degrease query_cache_size to find the value, which provides best performance for you. Note that as the query cache content gets invalidated with update queries, amount of memory which query cache can use is not unbound. Qcache_free_memory shows amount of free memory in query cache, which is not used at the moment. If this value stays constantly high during the load it might be good idea to decrease the query cache size, i.e. to free some memory from the query cache to other caches and buffers.
Other MySQL Tweaks
There are two other areas to be concerned about when tweaking, the Key cache and the Thread cache. Enter “SHOW STATUS LIKE ‘key%’;” at your mysql prompt to see what’s going on with your key cache. The ratio of actual reads to read requests should be in the 1:10 range. If you need to increase your key buffer, add:
key_buffer=2M
to your my.cnf.
Enter “SHOW STATUS LIKE ‘thread%’;” at your mysql prompt to see your thread cache info.
Just like Apache, MySQL creates a new instance to process requests. On modern systems, it creates threads; on other systems it makes forks. Either way, it keeps some on standby, just like Apache. The way to tweak this is to see how many threads it’s making and up the cache until it’s making just a few. If you increase it too much it will never make a new thread, which means you’re wasting memory with unused threads. Cover the common case and then work on the fringes.
If your threads_created number is in the thousands, you’re hemorrhaging memory. Increase the thread_cache_size in your my.cnf to a number about twice the number of connected threads and work from there.
Also, If you’re having problems with “too many connections”, raise your max_connections in your my.cnf.
Keep in mind that each of these settings affects and is affected by the others. It’s a balancing act, and tweaking takes a lot of testing and time. I can’t give you a magic formula, but I can tell you that you need to keep in mind how much memory you have available and remember that most of these numbers tend to have a direct correlation to memory usage.
Optimize MySQL
Optimising MySQL database’s is a doddle if you have access to PHPMyAdmin (it’s a good idea to backup your databases before you do this!):
- Click on the database your blog uses
- Click the ‘check all’ box at the bottom to select all tables
- Then click on the ‘Optimize table’ option in the drop-down box also at the bottom
From: Guide To Optimizing WordPress Servers » Connected Internet
Worpdress Specifics
WP-Cache2 is probably the most commonly prescribed cure for high-traffic blues. It’s an ingenious little system that does a better job of caching pages than Wordpress by itself can do. Be sure to turn off gzip compression if you use it. However, there’s more.
APC is a free PHP cache that can provide (allegedly) up to a 50% speed increase on your server. It’s actually not Wordpress specific, any PHP based site could get a boost out of it. The biggest downside is that you have to restart the server every time you change a PHP page. If you’ve finished working on your site for a while and are ready to let it run, APC might be a great choice. If you want to run it along side of WP-Cache, you’ll need to take a look at & APC « Mark on WordPress" >this article.
There’s a little-known plugin available called the Post Query Accelerator, as referenced here. In the words of the author:
The problem here is that the main post query uses ” AND post_date_gmt <= ‘$now’ ” … and $now changes on each load. qcache requires the query to be identical for it to be served from the query cache. And then I though… WHY does $now need to reflect the current time? The reason that $now is there is to prevent future posts from appearing, so why not just make that date reflect the date/ time of the most recently published post?
From: [wp-hackers] Freezing $now to increase query cache benefit
And that’s what the plugin does, it freezes $now and significantly reduces the time for queries. Try it, it worked wonders for me.
Addendum: As pointed out a couple of times now, the new version of Wordpress (2.1) now has this functionality built in. Thanks to everyone for keeping me on my toes.
Testing Under Pressure
I honestly don’t know for sure how to simulate the extended onslaught of a front-page Digg for testing purposes. I know there are ways, so if someone wants to enlighten me, feel free. In the meantime, a good testing method that gives you some feedback is to use:
ab -n 100 http://your.server/
at your terminal prompt, replacing 100 with whatever number of simultaneous hits you want to test for. While the test is running, have your web browser open and load a few pages to test responsiveness.
Go Forth and Multiply
If you have the power to tweak your server, hopefully this information will serve as a jumping point. I suppose it’s as important that we all write good content, but when we do, we should be prepared to handle the traffic that it can bring. So what do you say we get our servers whipped into shape and prove all those Digg naysayers wrong. 
-
01.23.07 / 7am
-
01.23.07 / 8am
Upgrading to 2.1 will have the same benefit you get from the freeze time plugin mentioned above. You’ll see a dramatic use of the query cache!
PS. your anti-spam measures aren’t working. This is my 3rd time typing this.
-
01.23.07 / 8am
Thanks for the tip, I’m testing 2.1 on a local server right now and plan to make the switch over the weekend.
I just disabled the current anti-spam feature, I’m not sure what it’s conflicting with but I’m having quite a few problems with plugins and wp-cache. Any suggestions for the best anti-spam measures? Bad Behaviour isn’t working with my new configuration, and I’m having a hell of a time with some of the other workarounds.
Also, does anybody know of a way to get Landing Sites to work with wp-cache? I don’t really want to manually include all of the plugin code and rewrite all of the database access functions manually…
-
01.23.07 / 8am
I’d recommend Akismet, but then I would wouldn’t I? ;) It works very well. It does let through a couple of spams occasionally when it hiccups, but it doesn’t happen very often.
Landing Sites - you could probably add the http_referer to the cache key? Or at least do the same checks Landing Sites does and add a string from the referer in the key.
-
01.23.07 / 8am
Alright, I’ve enabled Akismet, we’ll see how it goes ;-).
I’ll keep playing with Landing Sites. Seems like it would make a good addition to this post if I can get it working…
-
01.23.07 / 10am
[…] 23rd, 2007 · No Comments Here is a really handy article which talks about how wordpress could be optimized vai mysqlcaching and other usefull tricks. Okay, so thats on my todo list for the next week!. […]
-
01.23.07 / 11am
interesting article.
Regarding landing sites though… i’d love to find out a way to make the plugin work with wpcache and would really appreciate it if you’d share your solution with the rest of us if you work one out.
-
01.23.07 / 1pm
Saying anything is (Insert Verb) Proof is a huge leap of faith. See “Titanic”, “Hindinburg”….. for more info.
-
01.23.07 / 2pm
Agreed. I just needed something catchier than “More-or-Less Digg Resistant”. You’ll note I make no claims of absolute invincibility in the post, or guarantees of the same for my readers ;-).
-
01.23.07 / 3pm
Thanks for the tips. I was able to cut my mysq
-
01.23.07 / 4pm
Thanks for the tips. I was able to cut my mysql memory usage in half, which in turn gave me some more confidence to bump up my apache maxclients and maxrequestsperchild settings.
I’m still scratching my head over the key cache, though. My read:request ratio is more like 1:550.
-
01.23.07 / 4pm
nice, nice, nice, very nice! :-D enhancing mysql-performance by simply activating the query-cache has given my server a remarkable boost!
thanks4it! :-D
-
01.23.07 / 5pm
[…] Desweiteren habe Ich anhand dieser Beschreibung das MySQL-Query-Cache des Fantahost aktiviert. Dieses speichert die Anfragen an die Datenbank, so das diese vom Server nicht bei jedem Klick neu gestartet werden müssen. […]
-
01.23.07 / 6pm
[…] Here’s (yet) another guide to optimizing Wordpress, but it more sensibly goes into configuration of MySQL and Apache in some detail. […]
-
01.23.07 / 11pm
[…] Circle Six Blog » Blog Archive » DiggProof your Wordpress (tags: wordpress optimization) […]
-
01.24.07 / 12am
[…] 2. Anonymous on ‘Digg Proof Your Wordpress‘ […]
-
01.24.07 / 12am
[…] DiggProof your Wordpress (tags: wordpress) […]
-
01.24.07 / 5am
[…] DiggProof your Wordpress Alskens metoder til at goere sitet hurtigere. Kunne jeg godt faa brug for. (tags: apache traffic Wordpress) […]
-
01.24.07 / 7am
The query-cache-* variables use underscores instead of dashes.
-
01.24.07 / 7am
Just a minor correction/addition:
The query-cache-* variables use underscores instead of dashes.
Also, what Post Query Accelerator does is now included in the WP 2.1 mainline code.
-
01.24.07 / 7am
You are correct about the underscores, although it works both ways. I’ll edit the post, though, to avoid confusion. I found it both ways in various tutorials.
And yeah, I read that about 2.1 yesterday. I’m currently getting my plugins straightened out with 2.1 and PHP5 on a local server, which doesn’t give me much of a chance to battle test the actual speed of the database under load, so I’m looking forward to seeing it work!
-
01.24.07 / 3pm
[…] блоге Circle Six опубликована отличнаÑ? подборка Ñ?оветов по оптимизации Wordpress. Ð?втор подходит к решению […]
-
01.24.07 / 4pm
[…] DiggProof your Wordpress (tags: digg socialsoftware socialbookmarks wordpress mysql php) […]
-
01.26.07 / 5pm
Thanks for this! One of my customers pointed this article out, and I just implemented the MySQL changes. I host quite a few wordpress sites, so you just helped a lot of people. :)
-
01.28.07 / 11am
[…] Once I have gathered enough performance information, I will post an update with a screenshot. This post on CircleSix, mentioned previously, is a great place to […]
- 01.31.07 / 9am
-
02.05.07 / 2am
[…] Once I have gathered enough performance information, I will post an update with a screenshot. This post on CircleSix, mentioned previously, is a great place to […]
-
02.10.07 / 5pm
For some reason I can’t ever seem to get WP-cache to work.. is it compatible with wordpress 2.1?
Also to really speed up non dynamic content check out Apache .htaccess caching.
-
02.13.07 / 1am
Are you sure about having to restart Apache when using APC Cache? I’m using APC and haven’t had any issues. I change code all the time and it still runs super fast…
-
02.13.07 / 1am
That was my limited experience, but I didn’t give it much of a chance after reading about the downsides for people who change code often. Maybe I’ll have to take another look…
-
02.14.07 / 8am
[…] Circle Six Blog: DiggProof Your Wordpress Blog […]
-
02.19.07 / 1am
Administrare server
-
03.18.07 / 4pm
Thanks for sharing this great information that I have been searching since a long time and got it now. Very good advice for webmasters and good tips that I saw on these posts. Again, thank you very much.
I learned alot today. Thanks. -
04.15.07 / 8pm
[…] DiggProof your Wordpress […]
-
04.19.07 / 8pm
[…] DiggProof your Wordpress […]
-
04.30.07 / 12pm
[…] DiggProof your Wordpress […]
-
06.29.07 / 1am
valuable for me,thanks
-
08.20.07 / 8pm
hey i like your post very intresting
-
09.10.07 / 4am
Thanks very much! I have been searching for this for a long time and I finally found it. Thanks for the helpful tip. Keep it up…
-
09.17.07 / 9am
[…] Check your MySQL key cache.Check out your key cache in MySQL to see how yours is functioning. Ideally, the ratio of actual reads of your blog to requested reads should be in the range of 1:10. If it’s not, you can increase your key buffer. […]
-
09.18.07 / 1am
If you’re running eAccelerator or XCache, be sure to check these WordPress plugins out. They tie into XCache and eAccelerator’s variable cache and speed up your blog like crazy!
Feel free to add this to your article if you like.
-
09.18.07 / 10am
I'l be back… :)g
-
10.03.07 / 8pm
Interesting notes on Apache.
-
12.03.07 / 3pm
[…] How To Increase Your WordPress Site Performance (Without Losing Functionality) by 10 Times DiggProof your Wordpress Guide To Optimizing WordPress Servers Compressing php output with wp-cache2 WordPress […]
-
12.27.07 / 6am
Load balancing is probably the only way to go with high load wordpress blog. If you are getting dugg a lot running on one dedicated box will be not enough….
-
01.20.08 / 4am
[…] I know, it’s a ballsy headline, but I’m tired of hearing all of the … and other tips and plugins to make your Wordpress blog faster than it already is. … More Blog Resources […]
-
03.05.08 / 5am
thank u
i liked this article
-
03.09.08 / 3am
[…] DiggProof your Wordpress (Source: Circle Six […]
-
03.12.08 / 9am
I like the diggproof idea, hope I can get it to work soon!
-
03.13.08 / 2am
[…] DiggProof your Wordpress (Source: Circle Six […]
-
03.13.08 / 3am
[…] DiggProof your Wordpress (Source: Circle Six […]
- 03.15.08 / 1am
- 03.15.08 / 3am
-
03.15.08 / 7am
Simple rules:
1. MySQL query cache
2. Use mod_deflate and mod_expires module on Apache
3. Use eAccelerator (works without problems for PHP caching, and is much faster and more stable than APC kind of drivel) and Zend Optimiser
4. Finally, use WP-Super-Cache, which includes WP-Cache but more than that. Read up on their site and it’s fairly self evident which one you should use.
-
03.23.08 / 9am
[…] DiggProof your Wordpress (Source: Circle Six […]
-
04.27.08 / 11am
[…] Theme. 108. WP Contact Manager. 109. Wordpress and the custom fields, a overlooked feature. 110. DiggProof your Wordpress. 111. WordPress Ajax Commenting revisited. 112. Widgetizing Themes. (Source: Automattic.) 113. […]
-
05.10.08 / 11pm
Thanks for this useful tips…
However, I’m using wp-supercache currently and it has a digg-proof things. If I use methods in this article, will there be any conflict?
I’m hosting in a free webhosting (000webhost) and I really concern about cpu loads and such things to keep my site not banned.
Thanks a lot.
-
05.16.08 / 4am
[…] Theme 108. WP Contact Manager 109. Wordpress and the custom fields, a overlooked feature 110. DiggProof your Wordpress 111. WordPress Ajax Commenting revisited 112. Widgetizing Themes (Source: Automattic) 113. Cloaking […]
-
06.01.08 / 3am
I show your Blog our Webmaster.
Thanks a lot. -
06.01.08 / 8am
Many thanks. Implementing this for a Drupal site at http://barn.semper.se
-
06.06.08 / 6am
[…] Theme108. WP Contact Manager109. Wordpress and the custom fields, a overlooked feature110. DiggProof your Wordpress111. WordPress Ajax Commenting revisited112. Widgetizing Themes (Source: Automattic)113. Cloaking to […]
-
06.15.08 / 5am
[…] Make your blog Digg proof […]
-
06.15.08 / 10pm
[…] Make your blog Digg proof […]
-
06.18.08 / 8pm
[…] Make your blog Digg proof […]
-
06.22.08 / 11pm
[…] DiggProof your Wordpress — Circle Six Blog (tags: article blog digg tip) […]
-
06.23.08 / 11am
[…] Haz tu blog resistente al Digg Effect […]
-
06.23.08 / 12pm
[…] ????????? ????? ???????? - ??? ??????? ? ??? Digg.com […]
-
06.25.08 / 12am
[…] 15. Hacer que tu blog sea a prueba de Digg […]
-
06.27.08 / 1am
[…] Make your blog Digg proof […]
-
06.30.08 / 4pm
[…] Haz tu blog resistente al Digg Effect […]
-
07.02.08 / 3am
[…] DiggProof Your Wordpress […]
-
07.07.08 / 1am
[…] 12. DiggProof Your WordPress […]
-
07.11.08 / 9pm
[…] Anuncie seu Wordpress no Digg (Fonte: Circle Six […]
-
07.15.08 / 8am
[…] Make your blog Digg proof […]
-
07.17.08 / 3am
[…] Haz tu blog resistente al Digg Effect […]
-
07.24.08 / 11am
DiggProof your Wordpress
Have your say
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
76 Comments
Jump to comment form | comments rss [?] | trackback uri [?]