Created on Monday, 09 June 2014 15:41 09 June 2014

Dear Customers,

If a website could be seen as a chemical reaction of code, style sheet and content, then web accelerator tools like Varnish, Memcached and Node.JS could be treated as catalyzers that make the ingredients react faster and deliver better results.

In a series of articles we’ll focus on the main capabilities of those tools and will include an example of how you could use them to leverage on the huge catalyzing effect they could have on your sites’ performance. Let’s start with Varnish.

Varnish Accelerator is available on our hosting!Varnish Cache, also known as a caching HTTP reverse proxy, is a web accelerator that can considerably speed up a website by reducing the load on the server.

Why do I need Varnish if servers now work faster?

In theory, a server should return a response immediately without needing to do any real work in the background. In practice, however, the server may need to do a great deal of work before returning a response to the client. To execute a simple request, the server may need to start a new process, to load script files from the disk, to perform database queries, as well as many other actions that could exhaust the system resources.

And in the case of a poorly scripted site, the server response burden will get even bigger. This is just how web servers are made to work. No better solution has been invented so far.

Here is where web accelerators like Varnish come into play – they streamline the response operation. Their main mission is to cache the not-so-often-updated pages of content-heavy websites and to make them load faster. Depending on the site’s architecture, it can be sped up 300 to 1000 times its current speed.

How exactly does Varnish work?

When a request is sent to the server for the first time, it is first checked by Varnish and then forwarded to the server. The server then returns a response to Varnish, which in turn gives the response to the client that sent the original request. At the end of the process, Varnish stores the response from the backend in its cache for future use.

That response is stored in memory for faster access, instead of being cached to disk. This helps Varnish to quickly serve the next response directly from its cache and to eliminate the need for any action from the backend server.

As a result, the load will be reduced significantly, the response times will be improved, and the server will be able to handle more requests per second. All those optimizations allow Varnish to process server requests at an incredibly fast speed, which will give a direct boost to the performance of your sites and applications.

How do I activate Varnish in my site?

Working with Varnish requires a proper installation and a good control of its settings. We offer Varnish with all our web hosting plans, so our system will take care of the installation and memory allocation procedures.

Here is an example of how to create a basic Varnish instance on our servers.

Let’s say you want to use Varnish to cache your WordPress blog.

In the Varnish section of the Web Hosting Control Panel, click on the Create an Instance button on the top right.

In the popup window, select the memory allocation that you will need for this instance. By default, Varnish will scan your website traffic using a custom algorithm and, starting with the most visited pages, will cache your website content until the memory quota is reached. So, even if you exceed your memory allocation limit, your most sought-after pages will still be served:

Creating a Varnish instance - Memory allocation

Next, you need to select the dedicated IP address that we’ll use to set up the instance on. You could get one from the Service Upgrades section of the Control Panel. If you do not want to use a dedicated IP address, we will assign a specific port to your host. In this case, however, you will need to make sure that all static links to your blog are changed to reflect the port allocation:

Creating a Varnish instance - Dedicated IP address setup

NOTE: If you decide to use a dedicated IP address for the Varnish instance, you will need to point your WordPress site to that IP address from the Hosted Domains section of the Control Panel.

If you are well familiar with Varnish, you could make a manual configuration on your own by selecting the ‘Manual configuration’ option. Otherwise, we will do that for you automatically.

In general, cookies enabled for a site interfere with the proper caching of the content. This is why, if you have enabled cookies for your site, you will need to have them neutralized for the purpose of caching. You can do that by marking the ‘Remove cookies’ box, which will configure Varnish to ignore the cookies on your site automatically.

Creating a Varnish instance - Removing cookies

The TTL box refers to the time within which the cached content will be left in the memory. The default value is set to 60 seconds.

Finally, specify the URL(s) of your site that you do not want to be cached by Varnish. In our case, these should be the /wp-admin and /wp-login.php URLs of your WordPress site, which are input in the ‘Exclude URL’ field as follows:

Creating a Varnish instance - Excluding URLs

Varnish is included by default with all OpenVZ VPS and Virtuozzo VPS packages, semi-dedicated servers and dedicated servers.

All other packages offer it as an upgrade option. Also, you can always upgrade the current Varnish memory quota pertaining to your plan from the Service Upgrades section of the Control Panel.

Kind Regards,
Web Hosting team