{"id":729,"date":"2011-10-09T17:36:28","date_gmt":"2011-10-10T00:36:28","guid":{"rendered":"http:\/\/www.analogrithems.com\/rant\/?p=729"},"modified":"2011-10-09T17:38:24","modified_gmt":"2011-10-10T00:38:24","slug":"how-to-optimize-your-wp-ecommerce-site","status":"publish","type":"post","link":"https:\/\/www.analogrithems.com\/rant\/how-to-optimize-your-wp-ecommerce-site\/","title":{"rendered":"How to Optimize your WP eCommerce Site"},"content":{"rendered":"<p>I had a few people ask me how to really get the most out of their WP eCommerce site. \u00c2\u00a0On its own WordPress is actually a really fast\u00c2\u00a0efficient\u00c2\u00a0program. \u00c2\u00a0It&#8217;s not until we start adding on our fancy themes and useful plugins that it starts to bog down. \u00c2\u00a0Mix this with lots of traffic and you have a 500lb gorilla problem. \u00c2\u00a0It&#8217;s ok though because some amazing tools have been written to fix this. \u00c2\u00a0This post will show you how to optimize your WP eCommerce Site to get the most out of it. \u00c2\u00a0This method assumes you aren&#8217;t on a shared host or at least have the ability to install extra software and run additional services on your server.<\/p>\n<h1>Step 1<\/h1>\n<p>The first thing you need to do is download and install <a href=\"http:\/\/memcached.org\/\">Memcache<\/a>. \u00c2\u00a0Luckily\u00c2\u00a0in most distros their is a package for this. \u00c2\u00a0In Centos,Redhat and fedora you can install by simply doing the following.<\/p>\n<blockquote><p>yum -y install memcached libmemcached php-pecl-memcache<\/p><\/blockquote>\n<p>So a few things to note, one is we actually install multiple packages. \u00c2\u00a0The first one is the memcached server, the second one is a set of common client libraries and the last is the php library. \u00c2\u00a0You may at this point be wondering what is Memcache, great question. \u00c2\u00a0Memcache is a simple server that you run to cache data for you. \u00c2\u00a0It cuts down on the amount of SQL queries you do by caching them. \u00c2\u00a0It 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. \u00c2\u00a0 They claimed memcache caused an 80%\u00c2\u00a0improvement\u00c2\u00a0in performance.<\/p>\n<h2>How does it work?<\/h2>\n<p>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&#8217;t bother with the expensive db query. \u00c2\u00a0If it doesn&#8217;t you query the db and then tell memcache the result. \u00c2\u00a0That way next time you go to get that data you can get it from memcache which will be much faster than your database. \u00c2\u00a0This is important in ecommerce because on a single page load you can make over 700 sql queries.<\/p>\n<p>So once you have memcache installed, \u00c2\u00a0you need to configure it. \u00c2\u00a0I set my cache size to 1024. \u00c2\u00a0This makes is probably overkill for a single ecommerce site, but my server has plenty of memory and I feel it&#8217;s work it. \u00c2\u00a0If you installed via an rpm you&#8217;ll probably have a config file under <strong>\/etc\/<\/strong>\u00c2\u00a0for Centos\/Redhat it will be <strong>\/etc\/sysconfig\/memcached<\/strong>\u00c2\u00a0 See <a href=\"http:\/\/code.google.com\/p\/memcached\/wiki\/NewStart\">this page<\/a>\u00c2\u00a0for more documentation on memcached. \u00c2\u00a0Once you have it configured start the memcached service.<\/p>\n<blockquote><p>chkconfig memcached on<br \/>\n\/etc\/init.d\/memcached start<\/p><\/blockquote>\n<h1>Step 2<\/h1>\n<p>With memcached up and running it&#8217;s time to get the wordpress side configured to take advantage of this. \u00c2\u00a0Login to your dashboard as admin and go to the plugins section. \u00c2\u00a0Install the <a href=\"http:\/\/wordpress.org\/extend\/plugins\/w3-total-cache\/\">W3 Tototal Cache Plugin<\/a>\u00c2\u00a0and activate it. \u00c2\u00a0The click on the <strong>Performance<\/strong>\u00c2\u00a0tab of the left column.<\/p>\n<p>Enable the following and set the method to memcached<\/p>\n<ul>\n<li>Page Cache<\/li>\n<li>Database Cache<\/li>\n<li>Object Cache<\/li>\n<\/ul>\n<div><span style=\"font-size: small;\"><span class=\"Apple-style-span\" style=\"line-height: 24px;\">Don&#8217;t forget to click save settings.<\/span><\/span><\/div>\n<p>Click on the <strong>Page Cache<\/strong>\u00c2\u00a0link on the left and make sure that the memcache server configuration is correctly set. \u00c2\u00a0Do this again for <strong>Database Cache &amp; Object Cache<\/strong>. \u00c2\u00a0Once you are done visit a few of your public facing pages. \u00c2\u00a0At first you probably wont notice a performance increase until you or anyone clicks on those pages again. \u00c2\u00a0The 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. \u00c2\u00a0If after a few minutes you do get a noticeable page boost check the Trouble shooting section below<\/p>\n<h1>Summary<\/h1>\n<p>Using this method I got my page load times to go from 2500ms to 56ms. \u00c2\u00a0One thing to note is that when ever you recycle the memcache server you will need to rebuild your cache. \u00c2\u00a0This is often referred to as warming up the cache. \u00c2\u00a0I&#8217;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.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<h1>Trouble Shooting<\/h1>\n<p>To verify your memcached server is running and storing items properly from wordpress try the following.<\/p>\n<pre>root@vault events]#  echo \"stats cachedump 3 100\" | nc localhost 11211\r\nITEM test_15c03fbb2a8143d215b4204a3fec2bc8 [37 b; 1318205585 s]\r\nITEM test_a0b9d95d725c92d1f886bab92090476d [37 b; 1318205581 s]\r\nITEM w3tc_ecom-dev.analogrithems.com_1_object_31f40b57771bd6985c9ede7f4d365d81 [10 b; 1318207066 s]\r\nITEM test_2adea0d314e2e162e5808cf0cf89c93a [37 b; 1318205578 s]\r\nITEM test_0e9aeb2846e86ee40d7ef87f10983db7 [37 b; 1318205541 s]\r\nITEM w3tc_ecom-dev.analogrithems.com_1_object_d938afab08d705a5284e70001f04e078 [10 b; 1318207280 s]\r\nITEM w3tc_ecom-dev.analogrithems.com_object_887ca248c5dc568895f73a2da40408a0 [1 b; 1318207055 s]\r\nITEM w3tc_ecom-dev.analogrithems.com_1_object_9d8ea174ea710ccf7d1e137da3837713 [1 b; 1318207055 s]\r\nITEM w3tc_ecom-dev.analogrithems.com_1_object_b490861e41e39835d63036e06aac92ec [1 b; 1318207055 s]\r\nITEM w3tc_ecom-dev.analogrithems.com_1_object_2c16037bdfdf0b7f39dabc763607beed [1 b; 1318207055 s]\r\nEND<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I had a few people ask me how to really get the most out of their WP eCommerce site. \u00c2\u00a0On its own WordPress is actually a really fast\u00c2\u00a0efficient\u00c2\u00a0program. \u00c2\u00a0It&#8217;s not until we start adding on our fancy themes and useful plugins that it starts to bog down. \u00c2\u00a0Mix this with lots of traffic and you [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,21],"tags":[47,48,176],"class_list":["post-729","post","type-post","status-publish","format-standard","hentry","category-wordpress","category-wordpress-ecommerce","tag-memcached","tag-w3-total-cache","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/comments?post=729"}],"version-history":[{"count":8,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/729\/revisions"}],"predecessor-version":[{"id":764,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/729\/revisions\/764"}],"wp:attachment":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/media?parent=729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/categories?post=729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/tags?post=729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}