This is Part 2 of our Scaling for the Holiday Series. Click here to read Part 1: To Scale Vertically or Horizontally?
Caching is an easy way to speed up your application or website. Figure out what data you access frequently, and cache it in memory for repeated high-speed access to it. Whether your application is generating static content for web pages or storing sessions in caches, you have to decide how to store those caches. You can store the caches on your local file system or utilize distributed memory caches like memcached clusters.
If you use a file system to cache, you’re going to want a shared file system, especially for session data. Keep in mind that disk I/O is expensive compared to memory. A memcached server receives better performance.
Depending on what platform you’re running on, there are multiple ways you can implement caching. Here are a few at a glance:
Squid – http://www.squid-cache.org/
Varnish – http://www.varnish-cache.org/
PressFlow (for Drupal websites)- http://pressflow.org/
W3 Total Cache (for WordPress websites) – http://tools.rackspacecloud.com/applications/w3-total-cache/
For static content, another simple and beneficial solution is to publish to a CDN (Content Delivery Network) instead of the web server. You can do this easily with services like Rackspace Cloud Files, built with Akamai’s CDN technology. W3 Total Cache and PressFlow have built-in CDN technology. The files you elect to be public are shared over a content distribution network with locations all over the world. The first time your content is served to a user, a copy of the content is stored in cache on the edge servers closest to that user’s location. The next time the content is requested, its pulled directly from the cached copy on the edge servers, reducing delivery time. For example, all the images published to this blog are stored on Rackspace Cloud Files.
As always, make sure to take backups. You can use Cloud Files to back up your instance – just set up automatic cron jobs to make back ups of your MySQL data. I would recommend storing your source somewhere like github.
This series represents four important, and simple, things you can do to ensure your web application is ready for traffic surges. We will be talking about web server tuning next week and load balancing the week after. There are many other tactics others have had success with and we encourage you to leave those in the comments below.