Varnish

From wiki.mikejung.biz
Revision as of 20:26, 31 January 2013 by Admin (talk | contribs) (Commands and Arguments)
Jump to navigation Jump to search

Overview

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 really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture. A high level overview of what Varnish does can be seen in the video attached to this web page.

Configuration Files

  • Used for parameters and command line arguments. When you change this, you need to run service varnish restart for the changes to take effect.

Debian based

/etc/default/varnish 

Redhat / CentOS

/etc/sysconfig/varnish


  • This contains your VCL and backend-definitions. After changing this, you can run either service varnish reload, which will not restart Varnish, or you can run service varnish restart, which empties the cache.
/etc/varnish/default.vcl
backend default {
   .host = "localhost";
   .port = "8080";
}

Commands and Arguments

Restart Varnish and clear it's cache

service varnish restart

Reloads the vcl file, the cache is not affected

service varnish reload

Shows the cache status and hit ratio

varnishstat

Command line options.

Listen address
-a <[hostname]:port>

Specifies the vcl file location
-f <filename>

Set the tunable parameters
-p <parameter=value>

Authentication secret for management
-S <secretfile>

Management interface
-T <hostname:port>

Where and how to store objects
-s <storagetype,options>

Troubleshooting

nf_conntrack

If you notice some odd issues with Varnish, check dmesg, if you see this you should raise the limit.

# dmesg
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.

To raise the limit:

#See what the current limit is and note it:
cat /proc/sys/net/nf_conntrack_max

vim /etc/sysctl.conf

#Add the following
net.nf_conntrack_max = 100000

#Once that is added, run this to make the change permanent.
sysctl -p