X-Cache, W3 Total Cache and Varnish – Geek time..

After some tweaking and the right optimization website performance is up 3600%!!

After some tweaking and the right optimization website performance is up 3600%!!

I’ve hosted my own websites, and run my own servers for years. So it’s nothing new for me to understand load balancing and server management, but in the last 3-4 months my site readership has increased dramatically, really affecting web performance.

I’m a big fan of the open source movement, and utilize it extensively in my boxes. This site is hosted off a quad core x64 based hardware with 4GB ram. PLENTY for the Ubuntu 14.04LTS LAMP role I utilize it for.

For a quick primer, WordPress (this blog software) runs on an Apache/PHP/MySQL backend. I’ve done a lot of tweaking to optimize and multithread as much as I can in this box, but realized that my Achilles Heel is PHP itself.

X-Cache dramatically improves performance by acting as an OPCode and data cache.

X-Cache dramatically improves performance by acting as an OPCode and data cache.

PHP is a server side scripting language that’s used extensively in web development. It’s honestly the foundation of a large percentage of the websites you travel to daily. The issue with PHP, is that every time you ask the website to do anything, it has to read that programming code, compile it, and then execute it. That’s extremely expensive to the server, and when you guys hit me 40-80 requests at a time, you bring my poor little box to it’s knees. ­čśë

But that’s where X-Cache comes in. It’s what’s called an OPCode (Operational Code) cache. So, when something is compiled, X-Cache stores it all into a real time memory cache and serves it up as opposed to asking the PHP engine to recompile the same code again. You can see from the screen shot above that there have been tens of thousands of hits to the cache in less than 20 minutes. That’s tens of thousands of CPU cycles saved, improving performance by letting the CPU do other stuff.

W3 Total Cache - for WordPress

W3 Total Cache – for WordPress

X-Cache works hand in hand with a plugin for WordPress called W3 Total Cache (W3TC). This nifty little gem allows you to totally customize what is stored up in X-Cache (they are directly linked) as well. The nice thing is that there are extensive tutorials and online documents discussing how to integrate X-Cache and W3TC in your Apache/WordPress configuration.

The final segment here was how to stop Apache and PHP from continuously having to generate all these dynamic pages. Since I rarely EDIT a page once I’ve created it, those are instances where a more static approach to web design would be beneficial. The solution to this was to integrate a reverse proxy called “Varnish”. Sounds simple, but Varnish is actually used by Fortune 100 companies, high profile publication sites (I.E. New York Times), and it’s completely 100% free!

http://en.wikipedia.org/wiki/Varnish_(software) <-- Varnish HTTP accelerator software on Wikipedia.https://www.varnish-cache.org/ <- Varnish Cache main site.What Varnish does is it sits in front of my Apache instance, and it listens across the internet for requests. When you type in www.ProjectWRX.com, Varnish asks if a cached, static version exists. If not, it then goes to Apache (hidden behind the firewall now), and asks it to provide that page. Then, Varnish stores it for a definable period of time and serves it out. The integration is slick and seamless, and I've gone from being able to serve about a dozen pages a second, to about 3600 pages per second now!So, needless to say.. this little Quad core just scaled up considerably. So if you have that old computer laying around in your closet and it would struggle to run Windows Vista, or 7.... don't discredit it. *NIX derivatives like Ubuntu, Linux Mint, Debian, etc... all are wonderful, low resource needed alternatives that will stretch that hardware out for years!

Comments are closed.

See also: