Tarek Chaaban

Tarek Chaaban, M.Sc's official blog. It contains current web project portfolio, posts regarding his Canadian army experience, news, sports articles, and web tutorials on programming and using social networking technologies.

Load Balancing Varnish

Few weeks ago i made a post about varnish and what varnish was …

What is Varnish :

Varnish is an HTTP accelerator designed for content-heavy dynamic web sites. In contrast to other HTTP accelerators, many of which began life as client-side proxies or origin servers, Varnish was designed from the ground up as an HTTP accelerator. The Varnish web site claims that Varnish is ten to twenty times faster than the popular Squid cache on the same hardware.

Anyway , at my work i have to deal with varnish so i made few test and results were amazing (especially when you use jmeter) .

Varnish only works on Linux boxes , i have Ubuntu on one of my laptops and when i did the download i got the 1.0 version (the newest varnish version being 2.0.2)

so i had to manually do it on my ubuntu .

How to install varnish on ubuntu

if you want the old varnish version : just type in the command line : sudo apt-get install varnish

if you want the new varnish version :

  • Download the varnish .tar.gz from sourceforge
  • unzip it
  • using the command line go to the folder where you unzipped your files
  • type :
      1. 1- sudo ./configure
        2- sudo make
        3- sudo make install

that’s it !

Now you are ready to run the latest version of varnish !! cool eh ?

Next step is how to use Varnish … there is a difference between using the old and new varnish version .

In the old varnish you only had to write varnish start and the HTTP Accelerator would star and to stop it (varnish stop)

In the new varnish you have to start it this way :

You have to go to the folder where varnish is installed which is :

/usr/local/sbin/ then sudo ./varnishd -a 127.0.0.1:port -f /usr/local/etc/varnish/default.vcl -d

port : the port where you will see the tests (ex: launch your browser http://localhost:port)

-f : the VCL (varnish configuration file) , it’s where all the configuration will goes .

-d : to launch in debug mode

Next Step : Load Balancing varnish

Varnish is made for High traffic sites .

Open the default.vcl with you’re favorite text editor add these ligns :

backend java {
.host = “192.168.0.101″; // change for your site
.port = “8090″; // change the port
}

backend php {
.host = “192.168.0.101″;
.port = “80″;
}

sub vcl_recv {

if(req.http.host ~ “^localhost:[0-9]*/[A-Za-z0-9_]*.jsp$”) {
set req.backend = java;
}
else {
set req.backend = php;
}
}

In this case i’m doing simple stuff , just test if the query contain the call of a jsp file , if so forward it to the java backend , if it’s not the case forward it to the php backend .

you can put the regular expression that you want in the query .

in that case i’m only testing on same server , you can test using different server by changing the .host for the ip you want .

backend google {
.host = “google.com”;
.port = “80″;
}

// varnish might throw an error saying they found more than 1 ip … in that case use one of the ip’s mentioned.

Here are some of the questions i asked Varnish Support that might be helpful for other people :

1) How do we make varnish expire for some objects or part of a page (in another word how do we create an event to trigger to expire some caches and not all)

If you’re using ESI, each part is its own object and can be purged separately (from VCL or from the command interface).

ESI : EDGE SIDE INCLUDE (It’s a w3c Specification by Introduced by AKAMAI)

>we know that varnish can make pages very fast but what is the page serve performance of Varnish (any standard stats?)

Poul-Henning Kamp :

It depends a lot on the specific site, in particular what the cache
hit rate is, what kind of connectivity your clients have etc.

I think the highest number I have heard recently, in a synthetic
benchmark, was around 20k request/second and at least a couple of
sites report 300-400 megabit/s per server in live traffic.

>and are you going to make more documentation about VCL ?

Poul-Henning Kamp :

Yes, as soon as my application for 48 hours per day goes through :-)

We are working on the docs, but it does not go as fast as we want.

Tagged as: , , , , , , ,

2 Comments

  1. Why not get the highest availability while not getting caught in high prices? Kemp’s got some great load balancers that are low priced and high in quality:

  2. Because varnish is a “Free Open Source” while Kemps (the one that you call low price) varies between 2,500$ & 17,000$

    Cant beat Varnish !

Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.