Varnish Cache

Ashish aashisn at hotmail.com
Sat Apr 27 22:36:01 CEST 2013


Hi All,

I think it was due to the nature of the website, (i.e. cookies + json 
updates) were playing role not to cache.
I did some changes and it started working (for forced cache rule.)

e.g. sub vcl_recv  -> added some lookup for certain conditions.
  and sub vcl_fetch -> added set beresp.ttl

But going into another type of trouble: i occasionally get 503 thrown 
without any reason.
I have 2 server, i intentionally turned one off, health checkup shows 
its sick (great), and sends request to alive one, but 1 out of 20 times 
it throws 503.

_[I have added ulimit -n 10000 and restart for 4 times in 503, however 
is there any particular reason behind this behaviour?]
_
  4 RxURL        c /json/showcase/
     4 RxProtocol   c HTTP/1.1
     4 RxHeader     c Host: www.example.com
     4 RxHeader     c X-Real-IP: 188.223.122.81
     4 RxHeader     c X-Forwarded-For: 188.223.122.81
     4 RxHeader     c X-Forwarded-Proto: http
     4 RxHeader     c User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) 
AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
     4 RxHeader     c Accept: */*
     4 RxHeader     c Referer: http://www.example.com/
     4 RxHeader     c Accept-Encoding: gzip,deflate,sdch
     4 RxHeader     c Accept-Language: en-US,en;q=0.8
     4 RxHeader     c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
     4 VCL_call     c recv
     4 VCL_acl      c NO_MATCH unwanted
     4 VCL_return   c pass
     4 VCL_call     c hash
     4 Hash         c /json/showcase/
     4 Hash         c www.example.com
     4 VCL_return   c hash
     4 VCL_call     c pass pass
     4 FetchError   c no backend connection
     4 VCL_call     c error deliver
     4 VCL_call     c deliver deliver
     4 TxProtocol   c HTTP/1.1
     4 TxStatus     c 503
     4 TxResponse   c Service Unavailable
     4 TxHeader     c Server: Varnish
     4 TxHeader     c Content-Type: text/html; charset=utf-8
     4 TxHeader     c Content-Length: 715
     4 TxHeader     c Accept-Ranges: bytes
     4 TxHeader     c Date: Sat, 27 Apr 2013 15:51:25 GMT
     4 TxHeader     c X-Varnish: 619632706
     4 TxHeader     c Age: 0
     4 TxHeader     c Via: 1.1 varnish
     4 TxHeader     c Connection: close
     4 Length       c 715



On 27/04/2013 12:51, Ashish wrote:
> Hi , I am quite new on varnish, so far its been really impressive 
> doing test and quite everything that i wanted to achieve with it,
> I did some test with single server, and everything looked good, 
> interms of cache hit ratio and all. but now i am unable to see 
> anything as such as cache at all.
>
> Could anyone please show me pointer what in my rule is causing not to 
> cache?
>
> ( Things not working so far)
> # Cache as wished: /json/showcase 1s , robot.txt 4 days, CSS/JPG/JS/ 
> 3600s
> # If everything is busted serve whatever we got for 6 h
>
>
> => vcl
>
> ################## Define Backend Servers 
> ##########################################
> backend box1 { .host = "xx.xx.xx.xx"; .probe = { .url = "/"; .timeout 
> = 34 ms; .interval = 3s;    .window = 5;  .threshold = 3; } }
> backend box2 { .host = "xx.xx.xx.xx"; .probe = { .url = "/"; .timeout 
> = 34 ms; .interval = 3s;    .window = 5;  .threshold = 3; } }
>
> acl unwanted { "188.223.122.81"; }
>
> sub vcl_recv {  if (client.ip ~ unwanted) { error 403 "You seem to be 
> blocked man.";}
>
>                                              if (req.http.user-agent ~ 
> "^someuseragent")  {
>                 error 403 "If you think This is Mistake Please use 
> different User-Agent..";}
>             }
>
>
> ####################################### Start of Load Balancing 
> ########################
>
> director my_cluster random {
>
>         { .backend = box1; .weight = 2; }
>         { .backend = box2; .weight = 2; }
> }
>
> ###################################### ENd of Load Balancing 
> ############################
>
> ###################################### Start of Request Handling 
> ########################
> #sub vcl_recv {
>                 if (req.http.host ~ "^(.*\.)?myweb\.com$") {
>                     set req.backend = my_cluster;
>                     }
>
>                     if (req.request != "GET" &&
>                       req.request != "HEAD" &&
>                       req.request != "PUT" &&
>                       req.request != "POST" &&
>                       req.request != "TRACE" &&
>                       req.request != "OPTIONS" &&
>                       req.request != "DELETE") {
>                         /* Non-RFC2616 or CONNECT which is weird. */
>                         return (pipe);
>                     }
>                     if (req.request != "GET" && req.request != "HEAD") {
>                         /* We only deal with GET and HEAD by default */
>                         return (pass);
>                     }
>                     if (req.http.Authorization || req.http.Cookie) {
>                         /* Not cacheable by default */
>                         return (pass);
>                     }
>                      if (req.request == "GET" || req.request == "HEAD") {
>                     return (lookup);
>         }
>  }
>
>  ####################################### DO not cache anything on 
> probe ##############
>
>
> sub vcl_recv {
>    # This box fqdn is diff then above actual domains
>    if (req.http.host ~ "^(.*\.)?\.myboxes\.com$") {
>      return(pass);
>    }
> }
>
> ######################################### Start of forced TTL 
> ############################
> sub vcl_fetch {
>                if (req.url ~ "/json/showcase") {
>                 set beresp.ttl = 1s;
>                }
>
>
>                  if (beresp.http.cache-control !~ "s-maxage" && 
> req.url ~ "\.(png|gif|jpg)$") {
>                         set beresp.ttl = 120s;
>                  }
>
>                 if(req.url == "/robots.txt") {
>                 # Robots.txt is updated rarely and should be cached 
> for 4 days
>                 # Purge manually as required
>                 set beresp.ttl = 96h;
>                 }
>
>                 # Set TTL for these product
>                 if (req.url ~ 
> "\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)$") {
>                             unset beresp.http.set-cookie;
>                             set beresp.ttl = 3600s;
>                }
>
>                # Allow items to be stale if needed (i.e. if we are 
> down server wise).
>                set beresp.grace = 6h;
> }
>
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130427/140fd33c/attachment-0001.html>


More information about the varnish-misc mailing list