light

Al NemecDesigner & Developer

Varnish caching on a budget
Back to the list of posts

Varnish caching on a budget

Varnish caching on a budget

No matter how you create and manage your website, performance is always a key part of your sites success. It is no surprise that a slow website is likely to turn away visitors particularly on an e-commerce site. Time is money and customers don’t want to use slow sites.

So how do you know if your site is fast? Well there is always the natural perception of how it feels to navigate the site. But depending on how fast your ISP is you may be getting a false sense of speed compared to someone on a mobile device or living on a slower connection in general.

Thankfully there are a number of tools out there to help you determine if your site is lacking in certain areas on more measurable level.

These tools won’t know the way your site is structured but can at least give you a relatively objective look at your sites performance from the perspective of the visitor. In addition, they will help break down where some of the trouble areas are.

Improving performance depends on a number of factors and I won’t be going in to all of them on this post.

Caching

But I do want to talk about an area of performance that particularly affects many users using a content management system (CMS).  Your webserver is mostly likely running apache, mysql, and php. And if you are using a CMS like wordpress your website is causing your webserver to do a lot of processing every time someone visits the site. You can implement some disk based caching (such as the W3 Total Cache plugin for wordpress) but even this will only get you so far since apache is still handling the incoming requests.

Enter Varnish

Varnish is a web caching tool that lives independently of your website and serves up cached pages from memory when they are available.  The result is shockingly fast.

If you are using something like digital ocean (like I am) or another vps service your setup probably looks something like this.

prereq

 

What we would like to do is get to a setup that looks more like this.

goal

To give you an idea to the difference, here is a test I ran using blitz.io that pummeled a site living on a somewhat tiny 512Mb of memory Ubuntu 14 server on digital ocean.  In this test, disk caching has been turned on for a WordPress site.

Without Varnish

Screen Shot 2014-10-01 at 2.41.56 PM

In the test above the site got to about 300 users about 20 seconds in and crashed.

 

With Varnish

In this test I created a new VPS (also with 512Mb of memory on ubuntu 14) and set it as the varnish cache for the site.

Screen Shot 2014-10-01 at 2.44.05 PM

Tada! thats 28,922 hits with 0 errors and timeouts.  You can even see that at no point did the performance of the server slow down either.

Varnish has its downsides as it takes a while to configure properly and requires extra setup when utilizing https. But I think the benefits are clear.

If you want to be sure your site is likely to stay up with a large influx of users, I recommend you take a look at Varnish.  In my situation, I have this whole setup hosted for only $10 a month on virtual private servers.  For a more detailed guide on getting that setup, I recommend following digital ocean’s guide here.