Using varnish is quite simple, but configure and interpret varnish needs some time to understand. This section gives you the most important sources and commands to understand varnish better.

Varnish VCL

Varnish VCL is the most important part of varnish. In this file you can define the behaviour of varnish. For example what and how long a request gets cached. In the sources section are some links to get more familiar with a varnish VCL.


Watch and Interpret Varnish Metrics

If you want to check the health of varnish, you will use the tool varnishstat. There is a huge amount of metrics. The most important metrics can be viewed with this command docker exec -t <container-name> /usr/bin/varnishstat -f MAIN.sess_conn -f MAIN.client_req -f MAIN.sess_dropped -f MAIN.cache_hit -f MAIN.cache_miss -f MAIN.cache_hitpass -f MAIN.n_lru_nuked -f MAIN.n_expired -f MAIN.thread_queue_len -f MAIN.backend_conn -f MAIN.backend_fail -f MAIN.backend_unhealthy -f MAIN.backend_busy -f MAIN.backend_req -f SMA.s0.g_bytes -f SMA.s0.g_space

Client Metrics

sess_connCumulative number of accepted client connections by Varnish Cache
client_reqCumulative number of received client requests. Increments after a request is received, but before Varnish responds
sess_droppedNumber of connections dropped due to a full queue

Cache Performance

cache_hitCumulative number of times a file was served from Varnish’s cache
cache_missCumulative number of times a file was requested but was not in the cache, and was therefore requested from the backend
cache_hitpassCumulative number of hits for a “pass” file
n_lru_nukedLeast Recently Used Nuked Objects: Cumulative number of cached objects that Varnish has evicted from the cache because of a lack of space
n_expiredCumulative number of expired objects for example due to TTL

Thread Related Metrics

thread_queue_lenCurrent queue length: number of requests waiting on worker thread to become available

Backend Metrics

backend_connCumulative number of successful TCP connections to the backend
backend_failCumulative number of failed connections to the backend. Should be 0 or near 0
backend_unhealthyCumulative number of backend connections which were not attempted because the backend has been marked as unhealthy
backend_busyCumulative number of times the maximum amount of connections to the backend has been reached.
backend_reqNumber of requests to the backend
SMA.s0.g_bytesBytes of cache used
SMA.s0.g_spaceBytes of cache left