Tuning Varnish Cache

The FT recently sent me on a Varnish administration course run by Varnish Software; based just around the corner from our London office.

Varnishing the floor.

It was a brilliant two days of learning all about Varnish cache and the VCL language, making good useĀ of The Varnish Book for course material.

Here are some tips on tuning Varnish cache that we discussed during the course.


If you’re already running Varnish cache, I’d highly recommend getting to grips with the varnishstat CLI tool.

One feature of note is how by default the tool will hide counters with a 0 value. You can toggle the display of all the counters by pressing d. You can also find a list of all the counters in the reference manual.

The tool provides a great real-time view of the cache, but for historical stats you’ll need to export the data somewhere else.

varnishd Parameters

Several key statistics were highlighted during the course, all of which relate to a configurable varnishd parameter.

Looking at the sess_queued counterĀ in varnishstat, it’s described as the “number of times session was queued waiting for a thread”. Directly relating to the thread_pool_min parameter. If you’re seeing a large number of queued sessions, consider increasing the minimum number of threads to meet the typical number of connections varnish is receiving.

We then have sess_dropped, linking to the thread_pool_max parameter. If you see a number of dropped session, even after adjusting thread_pool_min, increase the value of thread_pool_max or spread the load between several varnish nodes.

Lastly there is the n_lru_nuked counter, which shows the number of objects that have been evicted from storage early to make room for new objects. If you see a value here, consider increasing the size of your cache for the storage type, the right size will mean a small to 0 value for this counter.