WordPress Scaling & Performance - A Picture Which Speaks Thousand Words and More

By Angsuman Chakraborty, Gaea News Network
Thursday, February 26, 2009

google-crawl-statsEveryone and their dog talks about WordPress performance these days and also tells you how to scale WordPress (Read: How to really scale WordPress). When I grew up in Kharagpur (yes, the same Kharagpur which has the top IIT and yes I did my B.Tech there) everyone knew how to cure diabetes - you have to walk a lot, stop eating sweets, eat / drink varying concoction of Neem leaves and / or Nayantara leaves and / or Jamun fruit or seed and presto you are cured of diabetes. It works to some extent in uncomplicated cases and so does the various remedies for WordPress performance. Let’s see what are the often repeated “expert” advice for making WordPress perform (because by default WordPress performance is really really crappy; pardon my French):

1. Use wp-cache 2 or wp-super cache. Most people who swear by wp super cache haven’t done rigorous performance test for either. They just like the idea that it generates static pages. In real life tests both perform very closely. Super cache doesn’t give you the boost that you would expect from a plain file cache. We preferred wp-cache 2 because 1. it is simpler and easier to install 2. in our tests it performed better in real load simulations.

2. Use php code accelerators like eAccelerator, APC, Zend or Xcache. In our tests as also around the web it has been found that eAccelerator performs best. It is also extremely stable despite what you may hear. Choose your poison but choose one. We use eAccelerator. However note that with caching the value of php code caching drastically diminishes in live load situation. You will find the bottleneck will more often be MySQL.

3. MySQL optimization Tons of tips have been written around the web about mysql performance and we too have contributed some in the past.Use them judiciously. Just remember not to use MySQL cache when you are using the WordPress caching plugin or other page caching software (for reasons explained later).

In the end you have to think about using multiple MySQL instances in a master-slave ( as WordPress.con does ) or master-master replication (notes). Interestingly, despite our heavy and ever increasing traffic, we managed to avoid it.

4. Use lighter & faster web server like nginx or lighttpd. In our tests and also others have found out that nginx and lighttpd consume much less resources and overall are faster than standard Apache installations. nginx is preferred these days because it doesn’t have a memory leak problem as lighttpd. Both run php using the fastcgi protocol which effectively isolate the web server from the vagaries of php code. Configuring nginx for WordPressto be equivalent with baseline Apache installation is much harder than Googling would lead you to believe. It has a steep learning curve and if not done thoroughly can affect your site in ways that you would never realize and may take months, if not more, to figure out and solve.

Now that we have most of the common tips behind us let’s look at their limitations. In heavy site load cached pages are served fine but even the limited amount of pages that are served in real-time is enough to bring your server to a crawl. With CPU at 0% idle (and MySQL can do it in tbe twinkle of an eye), all your site will be really slow, even when cached pages are being served. All the above techniques work well when there is some cpu and memory to spare.

MySQL can serve only about 40-50 WordPress pages even on a pretty high end server (2 processor quad core 2ghz cpu with 4gb of RAM) even with tuning. That is what you have to begin with.

MySQL caching, recommended by many experts, is a bad idea when you are using a caching plugin, examples given above, because most of the requests you are then serving is dynamic or unique (otherwise it is cached). So MySQL cache end up affecting performance and unnecessarily consuming resources.

The biggest problem with all these techniques described above is that you cannot ensure that your site will always serve pages to its available maximum bandwidth for any mix of static and dynamic requests.

Remember fail-whale in twitter. It is actually a good thing. Twitter knows when to deny requests when it can take no more. But we should strive for better, be able to take any amount (read very very large amount) of load you can throw at it.

You are always trying to compensate your server’s lack of reliability by throwing bigger and more hardware at it, without getting the full value for your money. You end up not only spending more but contributing to global pollution.

Previously I talked about how we achieved to serve over 10, 000 WordPress pages (from this blog so we are talking real data baby) per second at 1.6 Gbps and handle over 20, 000 connections per second without throwing a single error, all from a single server. How did we do it?

The key features of our architecture are:

  1. Ability to scale without limit
  2. Reliability under any amount and mix of load. No more server restarting in the middle of night.
  3. Ability to use the full CPU hardware & resources or less, under your full control
  4. Ability to provide similar performance even on low-end dedicated or VPS servers.

One thing that will probably make many LAMP aficionados cringe is that all the magic is done by a Java server in the middle. Our WordPress blogs (and now MODx sites) are all powered by Java too.

All talk aside, the proof of pudding is in eating. So how are we doing now? Take a look at the Google crawler stats at the top of this page which shows the time spent in downloading a page. Before February 6th not only it took a huge amount of time to serve a page but more importantly imho the time varied wildly depending on server load which indicates low reliability. After we switched to the new setup not only the time went down dramatically but also the wild fluctuations are gone. That indicates the reliability of our new setup. Also the traffic increased after the switch as we are not suffering from frequent overloading anymore and we are able to serve pages much faster.

July 7, 2010: 11:00 pm

Nice post..thank you

July 5, 2010: 4:11 am

never give up behold me as legend

June 5, 2010: 4:21 am

I read many blogs on a daily basis and under most situation, people lack substance but, I just wanted to make a quick comment to say GREAT blog!I’ll be checking in on a regularly now.Keep up the good work!

April 28, 2010: 6:19 pm

Great I really like your blog and I have learned something from it. Thank you very much for your post share.

March 11, 2010: 5:37 am

It’s an amazing, thanks for sharing.

January 26, 2010: 10:51 pm

Great information, Thank you so much… keep up the great work.

November 16, 2009: 1:48 am

I came across an excellent website that presents with up-to-date information regarding the destination information, safety and cultural tips, advice for women travelers. This helps the leisure travelers to plan for a safe vacation trip.

November 14, 2009: 2:04 am

Great post. It is very informative. I came across a website providing some valuable tips on destination information, safety and cultural travel tips and many more which could be useful for traveling in a unfamiliar destination.

November 12, 2009: 4:06 am

Marvelous post.. Thanks for providing such valuable information’s for which i have been searching for a long time.. Even i like to know useful safety tips for travel..

October 26, 2009: 12:37 pm

Looking for a good WordPress theme to use for my new blog. Happy to have found this site

September 1, 2009: 3:24 am

Whatever you have told is marvelous! You have a lot of good stuff here. I got so many useful point to here and you assisted me lot.

May 2, 2009: 12:22 am

this is such great information. i have been trying to get my wordpress site to load faster. i think i finally got it to work good. thanks for the tips.

April 27, 2009: 7:39 am

Whatever you have told is marvelous! You have a lot of good stuff here. I got so many useful point to here and you assisted me lot.

Thanks for wonderful assistance!

March 21, 2009: 5:39 am

Love your post!! Finally someone got it right!!! Would you mind if I put a blogroll link back to your post? :)

will not be displayed