4

I have a varnish installation to cache (MANY) images that my service serves. It is about 200 images of around 4k per second and varnish happily serves them according to the following rule:

if (req.request == "GET" && req.url ~ "\.(css|gif|jpg|jpeg|bmp|png|ico|img|tga|wmf)$") {
            remove req.http.cookie;
            return(lookup);
    }

Now, the thing is that I recently added another service on the same server that creates thumbnails to serve but it does not add a specific extension. The files are of the following filename pattern:

http://www.example.com/thumbnails/date-of-thumbnail/xxxxxxxxx.xx

where xx are numbers, so xxxxxxxxx.xx could be 6482364283.73 (two numbers at the end) (actually this is the timestamp so I can keep extra info in the filename)

That has the side effect that varnish does not cache them and I see them constantly being served by apache itself.

Even though I can change the format from now on to create thumbs ending in .jpg, is there a way to change the vcl file of my varnish daemon to either cache everything under a directory (the thumbnails directory) or everything with two numbers at its extension?

Let me know if I can provide any additional info !

Thanks!

2 Answers 2

3

A slight modification to your existing rule will do the trick:

if (req.request == "GET" && req.url ~ "^/thumbnails/") {
        remove req.http.cookie;
        return(lookup);
}

Or you could make the regex \.\d{2}$ if you wanted to cache everything ending with two digits.

3
  • Thanks a lot @womble!! It obviously worked. Now I think the problem is just hardware-related as I see a lot of LRU nuked when I do varnishstat. There are quite a few thumbnails (7 million), over one third of them used quite frequently, and they don't fit in the 8GB assigned to varnish :)
    – pataroulis
    Aug 4, 2012 at 18:04
  • 1
    That's an easy problem to solve -- RAM is cheap.
    – womble
    Aug 4, 2012 at 21:36
  • Ram is cheap but bringing down a production server to add it, is not usually, thus the whole workaround. (until I get a new one that is. Next one will have 96GB of course!) Thanks again!
    – pataroulis
    Sep 13, 2012 at 11:53
1

Think it's easier to go with matching thumbnails directory.

req.url ~ "\thumbnails\?.*" should be quite close.

I recommend you to read more about regular expressions and Varnish.

1
  • I don't know what you're trying to achieve with that regex, but I doubt you really want to match against a tab in the URL.
    – womble
    Aug 3, 2012 at 10:52

You must log in to answer this question.

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