I) What is Varnish?
Varnish Cache is a caching HTTP reverse proxy, really fast, and which is basically able to cache your page depending on the http headers set by the application.
However PrestaShop doesn't have a mechanism to control the HTTP header, and what should be cached / not cached. Hence, it's not possible to use Varnish with PrestaShop without some modifications.
II) The Softizy conditional caching module
Thanks to the work with our customers, we are now able to provide a module which enables the use of varnish with PrestaShop (working both with 1.6 and 1.7 version). It allows to control which pages should be cached, which cookies / context variable should be taken into account to generate another version of the page, the TTL, etc...
It has been successfully deployed on several websites. We will use
https://www.bobbies.com for our example here, using Varnish 5.2.
You can see an example of the headers sent for a cached page:
x-cache: HIT means varnish gets the page from its cache.
x-cache-hits: 510 means this version of the page has been served 510 times since it's in the cache
The Cache-Control shows the TTL of this page is 86400s (24h).
III) Varnish configuration
Of course just enabling the Softizy module is not enough, Varnish should be specifically configured to work with our module and PrestaShop, and the configuration is not easy. If you're using HTTPS (you should!), you also need to add a Nginx reverse proxy which will forward the HTTPS to Varnish which only handle HTTP on its free version. We take care of all those tricky configuration steps to adapt to our customers specific cases and achieve a really high level of performance which will absorb big traffic spikes.
IV) What are the performances?
Here is a benchmark which shows how fast is Varnish when the pages are served from the cache. After 100 concurrents users we actually suspect our benchmarks software 'siege' to saturate and to not show anymore the real numbers.
The command used to benchmark the website is the following :
siege -i -cXXX -b -t 20S --no-parser -f /etc/siege/urls-bobbies.txt
For this benchmark we used 3 urls : 1 from the homepage, 1 category, and 1 product page.
Transactions numbers with Varnish enabled on PrestaShop
Response time with Varnish enabled on PrestaShop
As you can see, Varnish provides up to 10x increase in transaction numbers at high concurrency, with a really low response time (worse was 0.19 at 200 concurrent users, which is really good!)
V) Conclusion
If you have performance issues with your prestashop and want to be able to handle a high number of concurrent users (be ready for Black Friday!), installing Varnish is a really interesting solution, as long as you set it up properly.
Feel free to
contact us to get our module and the information on how to configure Varnish and Nginx to achieve these results!
Contributors:
Jocelyn fournier
Jocelyn founded Softizy in 2015. He has worked on various large Websites over the last 15 years, including Hardware.fr, Doctissimo and Molotov.tv.
He is a long-time MySQL community member and a recognised MySQL contributor, with a deep knowledge of the MySQL internals, especially the optimizer.
His expertise in LAMP performance allows him to optimise large projects, from the PHP source code to the database.
[email protected]
https://www.softizy.com