DiggProof your Wordpress

Note: This post is over a year old. You may want to check later in this blog to see if there is new information.

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

Query Cache SettingsOne 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.

From: MySQL AB :: Tuning MySQL Server 4.0 Query cache.

Other MySQL Tweaks

Key and Thread CacheThere 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.

From: codepoetry - Optimizing a VPS for Getting Dugg

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 ScreenshotWP-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.

» » » »
  1. Weblog Tools Collection » Blog Archive » DiggProof your Wordpress 01.23.07 / 7am

    […] 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. […]

  2. Donncha O Caoimh 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.

  3. Brett Terpstra 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…

  4. Donncha O Caoimh 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.

  5. brett 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…

  6. Fine tuning wordpress performance « Virus In Training 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!. […]

  7. Ben 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.

  8. Stephen Flynn 01.23.07 / 1pm

    Saying anything is (Insert Verb) Proof is a huge leap of faith. See “Titanic”, “Hindinburg”….. for more info.

  9. brett 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 ;-).

  10. Dougal Campbell 01.23.07 / 3pm

    Thanks for the tips. I was able to cut my mysq

  11. Dougal Campbell 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.

  12. Mao-B 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

  13. Update auf WordPress 2.1 erfolgreich! at Phantastische Welten 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. […]

  14. Wordpress Performance Optimization by Elliott Back 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. […]

  15. Almost, Not Yet - links for 2007-01-24 01.23.07 / 11pm

    […] Circle Six Blog » Blog Archive » DiggProof your Wordpress (tags: wordpress optimization) […]

  16. Socially Driven Today, 01-23-2006 01.24.07 / 12am

    […] 2. Anonymous on ‘Digg Proof Your Wordpress‘ […]

  17. Skylog » Blog Archive » links for 2007-01-24 01.24.07 / 12am

    […] DiggProof your Wordpress (tags: wordpress) […]

  18. links for 2007-01-24 at Webmercial.dk: wordpress, weblogs, new media, streaming, film+internet, social media m.m. 01.24.07 / 5am

    […] DiggProof your Wordpress Alskens metoder til at goere sitet hurtigere. Kunne jeg godt faa brug for. (tags: apache traffic Wordpress) […]

  19. moeffju 01.24.07 / 7am

    The query-cache-* variables use underscores instead of dashes.

  20. moeffju 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.

  21. Brett Terpstra 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!

  22. Владимир Яшников » Digg Proof Wordpress 01.24.07 / 3pm

    […] блоге Circle Six опубликована отличная подборка советов по оптимизации Wordpress. Автор подходит к решению […]

  23. [i:rrhoblog] » links for 2007-01-24 01.24.07 / 4pm

    […] DiggProof your Wordpress (tags: digg socialsoftware socialbookmarks wordpress mysql php) […]

  24. Michal 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. :)

  25. Weblog Tools Collection » Blog Archive » Upgraded to WP 2.1 Ella 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 […]

  26. RomiSatriaWahono.Net » Optimisasi Wordpress di Server Traffic Tinggi 01.31.07 / 9am
  27. Hacks, Information, and More » Upgraded to WP 2.1 Ella 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 […]

  28. Caleb 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.

  29. Casey Woods 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…

  30. Brett Terpstra 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…

  31. Link Tank—Humpday Linkage | Pop Stalin Designs’ Design Blog 02.14.07 / 8am

    […] Circle Six Blog: DiggProof Your Wordpress Blog […]

  32. server 02.19.07 / 1am

    Administrare server

  33. I am Single 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.

  34. Wordpress Performance: Why My Site Is So Much Faster Than Yours by Elliott Back 04.15.07 / 8pm

    […] DiggProof your Wordpress […]

  35. Good List Of WordPress Optimisation Links | Connected Internet 04.19.07 / 8pm

    […] DiggProof your Wordpress […]

  36. Rick Retardo » Blog Archive » Good List Of WordPress Optimisation Links 04.30.07 / 12pm

    […] DiggProof your Wordpress […]

  37. led 06.29.07 / 1am

    valuable for me,thanks

  38. $$$$$$$$ 08.20.07 / 8pm

    hey i like your post very intresting

  39. Michael 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…

  40. Virtual Hosting » WordPress on Speed: 17 Tweaks to Accelerate your WP 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. […]

  41. Mark Jensen 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.

  42. Helga 09.18.07 / 10am

    I'l be back… :)g

  43. Dave 10.03.07 / 8pm

    Interesting notes on Apache.

  44. ??????????? ?????????????????? WordPress 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 […]

  45. Blog guy 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….

  46. WP-SuperBlog.com » Blog Archive » More Wordpress Blog Resources 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 […]

  47. mhmdk2003 03.05.08 / 5am

    thank u

    i liked this article

  48. 63 Essential Wordpress Hacks, Tutorials, Help Files and Cheats | Speckyboy - Wordpress and Design 03.09.08 / 3am

    […] DiggProof your Wordpress (Source: Circle Six […]

  49. Mike 03.12.08 / 9am

    I like the diggproof idea, hope I can get it to work soon!

  50. 63 essenziali Wordpress Hacks, Tutorials, Help Files e Cheats : technorati.it 03.13.08 / 2am

    […] DiggProof your Wordpress (Source: Circle Six […]

  51. Wordpress Tutorials/Hacks « The house of software freeware 03.13.08 / 3am

    […] DiggProof your Wordpress (Source: Circle Six […]

  52. Joe 03.15.08 / 1am
  53. Heel 03.15.08 / 3am
  54. Shanx 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.

  55. 63 Essential Wordpress Hacks, Tutorials, Help Files and Cheats | Speckyboy - Wordpress and Design » ???(JASMIN) 03.23.08 / 9am

    […] DiggProof your Wordpress (Source: Circle Six […]

  56. 155 Wordpress Resources, Tutorials, Plugins, Themes, AJAX, Podcasting…WP Monster List | Speckyboy - Wordpress and Design 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. […]

  57. Sukses 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.

    Sukses

Have your say

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>




Safari hates me