What is Varnish and Turpentine?
Also known as “caching HTTP reverse proxy”, Varnish can increase a website’s speed while simultaneously reducing the load on the web server. Ideally, a web server receives HTTP requests and gives back HTTP responses almost instantly. In this process, many identical responses are also delivered by the web server. But with Varnish, this website is able to run more efficiently as it caches these identical responses rather than generating them. When Varnish is in place, the HTTP request made by the customer will first reach to Varnish rather than directly going to the web server. As Varnish is a reverse web caching system, it will interpret all queries before reaching the web server. The back-end server will do its regular work and in turn send a response to Varnish which will then send a response to the customer who gave the original response. The result is that it will boost the performance of the back-end server by reducing its load thereby increasing the response time and speeding up the website. Varnish focuses on websites created by HTTP and is compatible both with dynamic and static content.
Turpentine on the other hand is an open source Magento extension that helps configure Varnish on your system. It is used to configure Varnish in Magento and helps to utilize its functionality in Magento. This extension works in two parts; page caching and block caching. For blocks, this extension looks out for the “core_block_abstract_to_html_before” event in Magento. When this event is triggered, the extension looks at the block attached to it and if an ESI policy has been defined for the block then the block’s template is replaced with a simple ESI (or AJAX) template that tells Varnish to pull the block content from a separate URL. This means extension is actually using this event in Magento to get more data and process it for caching purpose in Varnish.
How do they benefit a Magento store?
Caching is a technique which stores files for future use. Storing files can improve speed by making these files readily available rather than downloading or requesting them again. This loads our webpage faster, increases response time, reduce bandwidth and server load.
For Magento stores, this caching is taken to another level by Varnish. Varnish helps to reduce unnecessary usage of web server resources and thus generating web pages faster for website built on Magento. Using Varnish all your pages will be fully cached and speed up the efficiency of your Magento store.
But Varnish cannot cache requests with cookies by default and Magento needs to send the frontend cookies with every request causing a zero hit-rate for Varnish’s cache. Turpentine configures Varnish to work with Magento and modifies Magento’s behaviour to notably improve the cache hit rate. Turpentine uses a smart hole punching ESI block system to make sure all dynamic blocks are also loaded properly.
When using Varnish + Turpentine for your Magento store, your load time will go down drastically.
Steps to Configure Varnish for Magento 1.x:
Installing Turpentine works best with Magento Connect Manager:
Log on to your backend
Navigate to System > Magento Connect > Magento Connect Manager
Fill in your admin credentials
Paste the following key in the field next to Paste extension key to install: https://www.magentocommerce.com/magento-connect/turpentine-varnish-cache.html
Turpentine will now be installed
Log off and on again so Turpentine will appear in your admin
Flush your Magento cache via the backend (System → Cache Management)
Steps to configure Turpentine
After installing Turpentine and flushing the Magento cache, you can start configuring Turpentine:
First of all get the Varnish version , Varnish server list, Varnish authentication key values for your server.
Log on to your Magento backend
Navigate to System -> Configuration
Select Varnish Options under Turpentine
In the Servers section, fill in the following information:
Varnish version: leave this on ‘auto’
Varnish server list: Paste the content from your Service Panel here
Varnish authentication key: Paste the content from your Service Panel here
Select Caching Options under Turpentine
Check if the following information is correct:
Backend host: This should say varnish
Backend port: This should say 8080
Crawler ip’s: Remove localhost/127.0.0.1 from the crawler ip’s
Navigate to System -> Cache Management
Enable >Varnish Pages and >Varnish ESI Blocks
Click Apply Varnish Config below to complete the configuration