Why Varnish Rocks (and details on Boston training)

We are big fans of Varnish Cache, the incredibly fast and flexible open-source, caching software. Varnish delivers a significant fraction of the content for our Acquia Hosting and Drupal Gardens users.

Traffic spikes often occur when a widely read site links to a page on your site. Varnish shines in this scenario. Since those page requests are usually anonymous and limited to just a few URLs, Varnish can deliver these pages directly and the requests are never passed through to the back-end web server and database. Of course, there are a few Drupal configuration gotchas to make this work in practice (see below).

Here's what I like about Varnish:

  1. Speed: The core C engine is extremely fast and efficient. The Varnish team just blogged about achieving 275,000 HTTP requests per second!
  2. Configurable: Varnish really stands apart from its peers with its rich configuration language (VCL). With VCL, you can specify rules for every part of the pipeline based on any HTTP header. We've used VCL to cache distinct pages based on browser type, to implement edge side includes (ESI), to combine caches across multiple URLs, and to ignore specific cookies. To make this fast, Varnish translates VCL into C which it then compiles and executes. Even complex rule sets don't significantly slow response time.
  3. Supported, Open Source: It's open source, which we love. Plus, there is a strong dev and support team behind it which makes my job easier when we run into the inevitable snafus. Varnish Software is an Acquia Technology Partner.

Boston Training Class
For anyone in the Boston area, we invite you to attend the Varnish Training Class we are hosting in our offices next Monday and Tuesday (Nov 1-2). It's taught by senior Varnish engineer, Kristian Lyngstøl, and goes quite deep on how to configure Varnish. Check it out and register here.

Using Drupal with Varnish
By default, Varnish doesn't cache pages when cookies are set. Alas, out-of-the-box all versions of Drupal prior to D7 set a SESS cookie. To work around this limitation, I recommend installing the PressFlow extensions which disable the SESS cookie for anonymous sessions. Fortunately, Drupal 7 corrects the problem and doesn't set SESS cookies for anonymous page requests. Watch out for other sources of cookies. Quite a few Drupal modules and javascript-based marketing plugins (e.g., Google Analytics, Omniture, Woopra, etc.) also set cookies which cause cache misses.

Summary
Varnish dramatically speeds up cacheable pages. It's configurability can't be beat. If you're building a high-traffic Drupal site, consider including Varnish in your hosting stack.