Comparing Varnish and Nginx as Reverse Proxy for Magento 1.9 Store

Updated 14 June 2017

So, you have built your e-commerce website. Server is handling clients request, web pages are flashing on the screen and everything looks just fine. But as we gradually ascends towards the bigger picture where we deal with heavy traffic or large number of clients accessing the website and other big figures, we can feel that our website lacks something. You may find that page loading time, request response time or other load handling capabilities are not up to the mark. This is what we say that our website isn’t properly optimised.
High-traffic websites must support hundreds of thousands of users in a fast, reliable manner. A reverse proxy server acts as boon to this crises.

A reverse proxy server typically sits behind and directs client requests to the appropriate back-end server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.

Both Varnish and Nginx provide this solution. They ensure our e-commerce websites suited up with load balancing, web acceleration and also security and anonymity.
Depending upon website needs they can be preferred over one another. As when it comes to varnish, it acts as a http accelerator, provides optimum caching and load balancing. Varnish doesn’t allow SSL and is applicable only to port 80 and use host operating system’s memory management abilities and threading abilities to cache content at higher capacities, providing an excellent caching.
Nginx creates a fast looping mechanism that continuously checks and processes events so each worker only concerns itself with a connection when a new event is triggered. This means that Nginx does not create new threads for each request, handling multiple connections and requests in one work processor. Nginx is applicable to both https and http connections, hence allows SSL and provide dynamic and static caching.

So question arises that which one is better, which one should be used for caching for our backend server?

Well it depends upon the amount and kind of traffic your e-commerce website faces and what kind of contents your website carry.

To solve this very same query I have tested these packages on Vagrant machine using Siege tool on Magento 1.9.2 framework by setting up three cases:
(1) Magento 1.9.2 without any reverse proxy server,
(2) Magento 1.9.2 with Varnish 3.0.5 as a reverse proxy server, and
(3) Magento 1.9.2 with Nginx 1.4.6 as a reverse proxy server,

along with:  MySql 5.5, PHP 5.5, Redis-Server 2.8.4, and
Apache 2.4.7 as a backend server
OS: Ubuntu 14.04 LTS.
RAM: 3 GB

**Default settings are used in configuration files of Varnish and Nginx**

**Redis being mentioned here is an in-memory data structure store. It is based on single-threaded lock-free architecture. When first time page is loaded, a database is queried on the server. Redis caches the query. Next time other user loads the page the results are provided from the redis without querying the actual database**

I have tested all these cases with 100, 500 and 1000 concurrent users on HOME page, SEARCH RESULTS page and CHECKOUT CART page of my e-commerce website.
Also, the factors under considerations from siege results are Availability, Transaction Rate, Throughput and Response Time. The statistics obtained are as follows.

(a) HOME page :

Home page is the first page you encounter when you hit a website URL. The bar charts shows statistics of  parameters under observation when concurrent users are 100, 500 and 1000 respectively. We can observe that availability of our e-commerce website is 100% for all the three cases when 100 concurrent users try to access the website. Availability varies as we increase the number of concurrent users. Also throughput, response time and transaction rates shows favourable response for nginx in comparison to varnish.

(b) CHECKOUT CART page:

Checkout cart is the page you see when you have selected items to be bought and ready to proceed to payment options. This page contains heavy contents and caching is dynamic. So all the parameters varies as we change number of concurrent users. Performance of proxy servers seems to exceeds/lags over one another with different parameters under consideration.

(c) SEARCH page:

Contents of Search results page depends upon settings of number of products to be displayed on a single page.Load varies with increase in number of products. So with increased load, as we increase number of concurrent users accessing the website, our results differ significantly with other pages.               

Things work fine with 100 concurrent users but Availability decreases for each cases as concurrent users are 500 and drops significantly when they are 1000. Also transaction rates get reduced for search results. Throughput and response time are also below optimum level as concurrent users are above 500.

Both Varnish and Nginx have their differences which might be acceptable in some cases and not in others. As nginx has an advantage of providing caching over secure connection with low power consumption, Varnish provides good caching over http connections and acts as http accelerator which speeds up your website for static content. Nginx can tolerate higher number of concurrent users. It has the total solution for all your server needs (web server, static and dynamic cache, load balancing + mail proxy), and Varnish is just an another proxy caching mechanism.

Varnish can be a good alternative to Nginx as Proxy if you use Apache web server without any kind of caching, but lacks SSL support with SPDY and HTTP. This is another downside of Varnish: it consumes more CPU and RAM than Nginx.we can see that Nginx with redis-server can provide better results.

But varnish performs excellently when it comes to static caching. Also when Varnish is patched up with turpentine (a full page cache extension for magento), it significantly improves the cache hit rate. Optimisation of magento 1.9 with Varnish and Turpentine can deliver better results.

It is worth mentioning that all these experiments are conducted with magento 1.9.2 and statistics being presented here depend upon accessability of specific pages of website under heavy traffic. You might find different results for nginx and varnish when they are integrated with magento 2.x with different factors of consideration.

Different users might have different preferences in reverse proxy servers. Kindly share your views regarding the performance of reverse proxy servers in optimisation of the website.

 

IN CASE OF ANY QUERY,CONTACT US

Category(s) Uncategorized
author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home