I had a few people ask me how to really get the most out of their WP eCommerce site. On its own WordPress is actually a really fast efficient program. It’s not until we start adding on our fancy themes and useful plugins that it starts to bog down. Mix this with lots of traffic and you have a 500lb gorilla problem. It’s ok though because some amazing tools have been written to fix this. This post will show you how to optimize your WP eCommerce Site to get the most out of it. This method assumes you aren’t on a shared host or at least have the ability to install extra software and run additional services on your server.
The first thing you need to do is download and install Memcache. Luckily in most distros their is a package for this. In Centos,Redhat and fedora you can install by simply doing the following.
yum -y install memcached libmemcached php-pecl-memcache
So a few things to note, one is we actually install multiple packages. The first one is the memcached server, the second one is a set of common client libraries and the last is the php library. You may at this point be wondering what is Memcache, great question. Memcache is a simple server that you run to cache data for you. It cuts down on the amount of SQL queries you do by caching them. It was originally created by some smart folks at Live Journal to try to ease up on the extreme load they were putting on their databases. They claimed memcache caused an 80% improvement in performance.
How does it work?
Basically when you need to get some data from your database you check if memcache has that data first, if it does you take that and don’t bother with the expensive db query. If it doesn’t you query the db and then tell memcache the result. That way next time you go to get that data you can get it from memcache which will be much faster than your database. This is important in ecommerce because on a single page load you can make over 700 sql queries.
So once you have memcache installed, you need to configure it. I set my cache size to 1024. This makes is probably overkill for a single ecommerce site, but my server has plenty of memory and I feel it’s work it. If you installed via an rpm you’ll probably have a config file under /etc/ for Centos/Redhat it will be /etc/sysconfig/memcached See this page for more documentation on memcached. Once you have it configured start the memcached service.
chkconfig memcached on
With memcached up and running it’s time to get the wordpress side configured to take advantage of this. Login to your dashboard as admin and go to the plugins section. Install the W3 Tototal Cache Plugin and activate it. The click on the Performance tab of the left column.
Enable the following and set the method to memcached
- Page Cache
- Database Cache
- Object Cache
Click on the Page Cache link on the left and make sure that the memcache server configuration is correctly set. Do this again for Database Cache & Object Cache. Once you are done visit a few of your public facing pages. At first you probably wont notice a performance increase until you or anyone clicks on those pages again. The next time the page loads it will have a lot of the information now stored in memcache and wont need to fetch nearly as much from the DB. If after a few minutes you do get a noticeable page boost check the Trouble shooting section below
Using this method I got my page load times to go from 2500ms to 56ms. One thing to note is that when ever you recycle the memcache server you will need to rebuild your cache. This is often referred to as warming up the cache. I’ve created small wget script to spider my sites and cause the cache to get get built quickly so when customers hit the pages they are already cached.
In the future the WP eCommerce is working on optimizing their pages by combining several of the sql queries to reduce the overall calls to the server. In the meant time a lot can be gained by using the method outlines here.
One thing I should also add is make sure that you limit access to your memcached service via firewalls to make sure only your webservers have access to get and set vaules in it.
To verify your memcached server is running and storing items properly from wordpress try the following.
root@vault events]# echo "stats cachedump 3 100" | nc localhost 11211 ITEM test_15c03fbb2a8143d215b4204a3fec2bc8 [37 b; 1318205585 s] ITEM test_a0b9d95d725c92d1f886bab92090476d [37 b; 1318205581 s] ITEM w3tc_ecom-dev.analogrithems.com_1_object_31f40b57771bd6985c9ede7f4d365d81 [10 b; 1318207066 s] ITEM test_2adea0d314e2e162e5808cf0cf89c93a [37 b; 1318205578 s] ITEM test_0e9aeb2846e86ee40d7ef87f10983db7 [37 b; 1318205541 s] ITEM w3tc_ecom-dev.analogrithems.com_1_object_d938afab08d705a5284e70001f04e078 [10 b; 1318207280 s] ITEM w3tc_ecom-dev.analogrithems.com_object_887ca248c5dc568895f73a2da40408a0 [1 b; 1318207055 s] ITEM w3tc_ecom-dev.analogrithems.com_1_object_9d8ea174ea710ccf7d1e137da3837713 [1 b; 1318207055 s] ITEM w3tc_ecom-dev.analogrithems.com_1_object_b490861e41e39835d63036e06aac92ec [1 b; 1318207055 s] ITEM w3tc_ecom-dev.analogrithems.com_1_object_2c16037bdfdf0b7f39dabc763607beed [1 b; 1318207055 s] END