Tuesday, March 22, 2011

Top 5 Varnish commands

Here's a brief list of my top 5 varnish commands

varnishstat
This is what I use to get a birds-eye view of what we have cooking. Provides all the info you need to spot cache misses and errors.
Usage: varnishstat for continuous display or varnishstat -i 1 for a quick one-off. More on this command: http://www.varnish-cache.org/docs/2.1/reference/varnishstat.html

varnishhist
Provides a histogram view of cache hits/misses
Usage: varnishhist More on this command: http://www.varnish-cache.org/docs/2.1/reference/varnishhist.html

varnishlog
Provides detailed information on requests. I use it to debug cache operations by for example issuing the command varnishlog -c -o ReqStart [insert ip here] which allows me to see what happens when I visit a cache object in my browser.
Usage: varnishlog -c -o ReqStart 192.168.0.1 More on this command: http://www.varnish-cache.org/docs/2.1/reference/varnishlog.html

varnishtop
I use this mainly to get lists of things. Like this one that gives me a list of the top urls hitting the backend (pass).
Usage: varnishtop -b -i TxURL More on this command: http://www.varnish-cache.org/docs/2.1/reference/varnishtop.html

varnishadm
Command-line varnish administration. I mainly use this to reload vcl and purge urls.
Usage: varnishadm -t host:port command
Reloading a vcl from the command line can be done like this:
Load (your changed vcl): varnishadm -t localhost:6082 vcl.load load01 /etc/varnish/default.vcl
Use (apply) the vcl: varnishadm -t localhost:6082 vcl.use load01
More on this command: http://www.varnish-cache.org/docs/2.1/reference/varnishadm.html

5 comments:

  1. Hi

    I have a URL(esi) which should never HIT the cache.

    How can I verify this with varnishlog?

    ReplyDelete
    Replies
    1. Aanchal, sorry for the late reply.

      If using Drupal, this would be it:
      varnishlog -x 'CLI' -x 'WorkThread' -x 'Debug' -o TxURL '^/esi/block/'

      If not, I'd guess placing a "log" statement before you call "esi;" in your VCL could be of some help

      Delete
  2. Christopher,

    I am using Varnish 2.x
    Just want to know how can I debug it, Is there anything like print_r that we have in php ?
    I want to see all the data contained in request object(req), similarly for other objects too...
    I am also using Varnish on Drupal 6 (pressflow).

    ReplyDelete
    Replies
    1. Mr Vaibhav Jain: There is no print_r for VCL, there is the possibility of using inline C code but I do think that the easiest way to dump a complete request is varnishlog -c -o ReqStart 192.168.0.1 which would give you all data for every request that comes from the client on that IP.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete