Varnish Cache for Magento: What You Need to Know

Published April 28th, 2014 by Michael Farin

EndLayer Varnish CacheWhat Is Varnish?

Varnish Cache is a web application accelerator, or reverse proxy web caching system, that caches server contents. It’s an HTTP reverse proxy server, which means it can store the contents of any server that speaks HTTP. (Reverse proxy servers return cached resources only from their associated servers – as opposed to forward proxy servers, which retrieve additional information from the Internet for their clients.)

Varnish is licensed under a two-clause BSD license (FreeBSD). There are two versions available: free and commercial.

How Does Varnish Work?

Varnish Cache takes a load off the back-end server by saving page request data once the page has been visited. Now, the next time someone goes to that page, they can just access the cached content from the Varnish server, instead of waiting for the HTTP server to retrieve the original page.

Each request is cached in the Varnish server’s memory, not on the hard drive – allowing repeat page requests to load instantly without accessing the server. It’s a little bit like keeping extra holiday decorations downstairs so you don’t have to go up and root around in the attic every year. Very convenient – and way, way faster than the alternative.

Varnish Cache saves database requests, CPU time and file look-ups, and can process hundreds more server requests per second. It allows you to avoid multiple database connections and PHP threads, and reduces response latency and CPU consumption.

How Fast Is Varnish?

Pretty darn fast. Installing Varnish Cache typically speeds up your page delivery by a factor of 300x to 1000x, depending on your configuration. Varnish’s performance is usually bound only by the network speed – meaning load speeds are virtually unlimited. Varnish regularly delivers 20 Gbps on off-the-shelf hardware.

Part of the reason for Varnish’s stellar speed: The cache is stored completely in memory, without using the disk. This optimization allows Varnish to process page requests lightning-fast – but you do have to be careful not to overload the cache. There’s a limited amount of memory space available, so make sure you’re not caching duplicate objects and wasting space.

Why Varnish?

First, you should understand what happens when you make HTTP requests without Varnish. The typical server goes through a long, convoluted series of steps before accessing your requested page. Here’s a typical sequence of events:

  1. Initiate a new process to handle the request.
  2. Load script files from the disk.
  3. Launch an interpreter process.
  4. Compile the script files into bytecode.
  5. Execute the bytecode.
  6. Perform additional database queries.
  7. Retrieve more files from the disk.
  8. Display the results.

And that’s all just for one page. Multiply that process by hundreds or even thousands of server requests, and it’s easy to see why many server responses are excruciatingly slow. Servers have no way of remembering if someone has accessed the same page earlier, so each time you visit the page, you have to process a new request. It’s kind of exhausting – and discouraging – just to think about it.

Varnish Cache bypasses all of those steps. By storing the data from prior server requests, Varnish can return an instant response for any pages with static content. If someone has visited the page before, Varnish Cache can pull up and serve that content instantly.

As you can imagine, this takes a huge load off the actual (backend) server. There’s more drive space available and everything moves more quickly. So the pages that the backend server does have to load (non-cached shopping carts, checkout pages, etc.) are able to cue up much faster.

Besides its speed, Varnish also has the advantage of an extremely flexible configuration language, VCL. VCL allows you to write policies that determine how to handle incoming requests, dictate which content to serve, and decide how to alter server responses and requests. Varnish can also be extended with a number of modules (VMODs).

Why Varnish + Magento?

Magento is one of the top e-commerce platforms available: extensive, flexible and feature-rich. It includes multiple site control from a single admin interface, multiple themes, single-page checkout and shipping to multiple addresses. (Visit the Magento site for a full list.)

Unfortunately, all those goodies mean Magento can be slow – much slower than non-ecommerce sites. Loading hundreds or thousands of inventory pages, making separate requests to the server for each page, can slow an e-commerce site way, way down. And you don’t want that.

Varnish Cache is perfect for speeding up your Magento site and adding light-years of speed to your servers. As you know, a faster Magento site means a whole lot of other benefits: better performance, increased search rankings and ultimately, more revenue.

And that’s the plain, unvarnished truth.

EndLayer’s Shared Performance Metal (SPM) Platinum Plan includes Varnish Cache as a built-in component.

Comments ()

Stay Connected

Contact Us

Phone: 1-855-363-5293 Email: info@endlayer.com

Endlayer.com Newsletter

Archives