Varnish – the web accelerator for content-heavy sites
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 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.
If servers now work faster, why is Varnish needed?
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?
Let’s see in more detail how Varnish works to streamline the server response.
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. In the process, Varnish stores the response from the backend in its cache for future use.
What’s more important, the 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 to work with Varnish?
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:
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:
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’ll 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.
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:
Varnish is included by default with the Corporate and the Enterprise hosting packages, as well as with all OpenVZ VPS and Virtuozzo VPS packages, semi-dedicated servers and dedicated servers.
All other packages offer it as an upgrade option. Also, customers can always upgrade the current Varnish memory quota pertaining to their plan from the Service Upgrades section of the Control Panel.
Originally published Monday, June 9th, 2014 at 3:41 pm, updated November 19, 2015 and is filed under Hepsia Control Panel.
Tags: web hosting, dedicated servers, web hosting control panel, semi-dedicated servers, Virtual Private Servers, web accelerators, OpenVZ VPS, Virtuozzo VPS
June 24th, 2014 at 4:11 pm
[…] tools that can give a significant boost to your sites and applications. The first article was about Varnish – the web accelerator for content loaded sites with irregularly updated […]
January 21st, 2015 at 10:28 am
If Varnish is included by default on some hosting plans, and cost quite much (!) on others, why is this not shown at the compare plans tables? Neither in resellerspanel CP or in stores.
January 21st, 2015 at 2:50 pm
Hello, the website accelerators (Varnish, Memcached and Node.js) are listed on our WordPress themes and are yet to be added to the Store Master theme with the implementation of a planned major theme update very soon.
January 21st, 2015 at 3:00 pm
Sorry, my bad. I see now that Varnish is there on the WordPress theme, but it does not say optional for Starter and Business plan. It really says that it is included! See my attachment.
January 21st, 2015 at 3:19 pm
Oh, I see what you mean. We’ll correct that and run an update of the plugin to get it live. I’ll keep you posted here on the case. Thank you for the heads up.
February 2nd, 2015 at 5:40 pm
Hello again, we’ve updated the ResellersPanel WordPress plugin to display the per-package listing of web accelerators correctly.