21

I've configured my Varnish cache to use a cache size of 512 MB, using:

varnishd ... -s file,/var/cache/varnish.cache,512M

Questions:

  • How do I monitor if 512 MB is too small, too big or okay?
  • How do I get the current usage size of the cache?
  • How do I see how often objects are removed from the cache due to the cache being full?

3 Answers 3

20

I found the solution:

You can monitor how much of the maximum cache size (512 MB in this case) that Varnish has allocated by running varnishstat. Then look for the output lines "bytes allocated" and "bytes free".

The following relation holds:

Command line configuration of max size = [bytes allocated] + [bytes free]

Depending on the size of "bytes free" you can fine-tune your cache size to find a proper level.

2
  • 15
    An even better indicator to watch is "n_lru_nuked" (varnishstat -1 -f n_lru_nuked) - it shows the number of objects nuked from the cache.
    – knorv
    Aug 26, 2009 at 15:15
  • 1
    varnishstat -f SMF.s0.c_bytes,SMF.s0.g_space
    – choonkeat
    Jun 17, 2015 at 14:11
16

Watch the n_lru_nuked counter. Each time it increases, Varnish throws something out of the cache because it is running low on storage.

Ideally, you wouldn't want the LRU counter to increase at all since kicking stuff out of cache usually means it must be re-fetched, but if your tail is long, LRU cannot be avoided.

2
  • what does if your tail is long mean?
    – cherouvim
    Mar 22, 2016 at 7:20
  • I think in this context it means if you have a lot of rarely-used items that end up in cache, taking up all the cache memory. It's a reference to this concept: en.wikipedia.org/wiki/Long_tail
    – cam8001
    Jun 7, 2016 at 12:09
1

Unless you expect all your data to fit in the cache, I'd look at the ratio of cache hits to cache misses. You get diminishing returns. Doubling the cache will probably halve your miss-rate, which is a big win when half your requests are uncached, not so much when 90% are.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .