RX > TX, not storing files in cache as long as it should

Dridi Boukelmoune dridi.boukelmoune at zenika.com
Tue Jul 1 11:10:24 CEST 2014


Hi,

On Mon, Jun 30, 2014 at 10:19 AM, Robin <imer at imer.cc> wrote:
> Hello,
> I recently set up a varnish cache to serve as an edge server to take some
> traffic load off our main server.
> What it's supposed to do is cache ~3GB (for now, will expand later) of
> static files which never change (new files will get a new url).
> This seems to work mostly ok, looking at the interface statistics after 2
> days of runtime it turns out it's actually recieving more data than its
> sending.
> One of our nodes shows (for example): RX bytes:119388151300 (111.1 GiB)  TX
> bytes:60809550709 (56.6 GiB)

This one will definitely not fit in your cache. Output from varnishlog
for those transactions might help figure what's going on. Varnish
might send it gzipped, which could explain the size difference but
that wouldn't make sense if this file is already compressed.

> The static files range from a few MB to (the biggest) 1.2GB, usually are
> around max. 100MB though.
> They are originally served using nginx with the "expires max" directive set,
> this is reflected by the varnish cache too:
> http://puu.sh/9Qq3A/6c934ad71c.png

According to this image, you have a cache miss.

> As you can see though, the Age is 0 - which means (from what I understand)
> the file didn't exist yet and is just being downloaded by varnish - which is
> not true.
> The file has been downloaded by that node multiple times, each time with a
> varying content length: http://puu.sh/9Qqds/506e73e589.png

Could it be because you generate the rar files on the fly in a
non-deterministic fashion? Although even with that size variations are
disturbing.

> My .vcl looks like this:
>>
>> backend default {
>>     .host = "backend ip";
>>     .port = "80";
>> }
>> sub vcl_fetch {
>>     if (beresp.ttl <= 0s ||
>>         beresp.http.Set-Cookie ||
>>         beresp.http.Vary == "*") {
>>                 /*
>>                  * Mark as "Hit-For-Pass" for the next 2 minutes
>>                  */
>>                 set beresp.ttl = 120 s;
>>                 return (hit_for_pass);
>>     }
>>     set beresp.do_stream = true;
>>     return (deliver);
>> }
>
> And the options passed to varnish are:
>>
>> DAEMON_OPTS="-a :80 \
>>              -T localhost:6082 \
>>              -f /etc/varnish/default.vcl \
>>              -S /etc/varnish/secret \
>>              -p send_timeout=86400 \
>>              -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,7G"

Which version of varnish are you using?

> Any idea why this is happening?
>>
>> n_lru_nuked                  0          . N LRU nuked objects
>
> Means the cache isnt filled up, which it shouldnt be anyways - so why is it
> downloading it over and over again and why is it aborting prematurely and
> not downloading the full file to cache?

Do you receive cookies? If those files are static (or semi-static) and
need to be cached, you need to either fix your backend to make sure
you set cookies only on relevant paths, or prune/ignore the irrelevant
cookies in vcl_recv.

> Trying to download the file always results in working files, so does it
> cancel the download to varnish if the user aborts? If so this is really
> disadvantageous for us, cause it may cause a large file to be downloaded
> multiple times before finally ending up in the cache
>
> Hope someone can help me out
>
> - Robin
>
>
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc



More information about the varnish-misc mailing list