Pages

Sunday, 8 April 2012

Varnish–Power Booster for Facebook


One thing most of people does not know is that, most of the Facebook request mostly does not reach the HDD i.e. hard disk.Most of the requests remain in the cache buffer of Facebook (Memcached for Facebook) .

We have seen what basically MemCached in one of the post , now the turn comes is of Varnish, the power booster which picks up every requests in Facebook and sends to the servers,that is it is a reverse proxy.


Varnish Request-Response ModelAbove photo shows  the best easy diagrammatic representation of how does Varnish work.Varnish is heavily threaded, with each client connection being handled by a separate worker thread. When the configured limit on the number of active worker threads is reached, incoming connections are placed in an overflow queue.Thereby only when this queue has reached its limit then the incoming connections will be rejected.

According to data known, there are following things occurring in Facebook in next 60 seconds :
6,96,000+ Facebook status updates, 5,10,000 comments.

Caching is vital for high-load applications. A typical web application serves a lot of content that costs much more to generate than it costs to cache (including the cost of checking and expiring the cache), so caching can usually improve performance by orders of magnitude.

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is too fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture.

It serves billions of requests every day to Facebook users around the world. Whenever you load photos and profile pictures of your friends, there's a very good chance that Varnish is involved.

A normal proxy redirects the server request through its proxy server, whether via LAN or anonymously and then sends the request to the concerned server. This helps to hide the identity of the original user.
In normal way the cache is more stored either on server.To avoid this a reverse proxy like Squid or Varnish is used.In reverse proxy the compression and load balancing of data is done on the client side.

One of the main feature ( and the BEST feature according to me) in varnish is that it has two modes in it,which makes it enormously useful to network administrators and web programmers to handle requests according to the behavior of   request.The following article will be posted  about that two modes.Until that time,read this article carefully.