Why my varnish create different cache object for different client?

Thirteen Fish fishthirteen at gmail.com
Wed May 14 18:40:15 CEST 2014


Every one, I'm a newbie for varnish and I need your help.

My varnish has an strange problem. It create different hash for same url
for different client, and this result in any new user which access my site
can't hit the cache.

>From the varnish log, I found the varnish hit different object though the
hash data is same. Following are the logs.


*Varnish Log From Client 1 (192.168.66.81)*

 1    14 StatSess     c 192.168.66.81 49278 0 1 0 0 0 0 0 0
  2    11 SessionOpen  c 192.168.66.81 49300 :80
  3    11 ReqStart     c 192.168.66.81 49300 1750481507
  4    11 RxRequest    c GET
  5    11 RxURL        c /Mainpage
  6    11 RxProtocol   c HTTP/1.1
  7    11 RxHeader     c Host: zh.moegirl.org
  8    11 RxHeader     c Connection: keep-alive
  9    11 RxHeader     c Cache-Control: max-age=0
 10    11 RxHeader     c Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
 11    11 RxHeader     c User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
 12    11 RxHeader     c Accept-Encoding: gzip,deflate,sdch
 13    11 RxHeader     c Accept-Language:
en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4
 14    11 RxHeader     c Cookie:
__utma=1.51232645.1400082743.1400082743.1400082743.1;
__utmb=1.1.10.1400082743; __utmc=1;
__utmz=1.1400082743.1.1.
utmcsr=(direct)|utmccn=(direct)|utmcmd=(
 15 none);
__gads=ID=d1f7dc9d52cd4a78:T=1400082743:S=ALNI_MbXhSNK0VtcUY7M9mjv8nanysdcbg
 16    11 VCL_call     c recv lookup
 17    11 VCL_call     c hash
 18    11 Hash         c /Mainpage
 19    11 Hash         c zh.moegirl.org
 20    11 VCL_return   c hash
 21    11 Hit          c 1750481502
 22    11 VCL_call     c hit deliver
 23    11 VCL_call     c deliver deliver
 24    11 TxProtocol   c HTTP/1.1
 25    11 TxStatus     c 200
 26    11 TxResponse   c OK
 27    11 TxHeader     c Server: nginx/1.6.0
 28    11 TxHeader     c Content-Type: text/html; charset=UTF-8
 29    11 TxHeader     c Vary: Accept-Encoding, Accept-Encoding, Cookie,
Accept-Language
 30    11 TxHeader     c X-Content-Type-Options: nosniff
 31    11 TxHeader     c Content-language: zh
 32    11 TxHeader     c Cache-Control: s-maxage=2678400, must-revalidate,
max-age=0
 33    11 TxHeader     c Last-Modified: Mon, 12 May 2014 20:01:11 GMT
 34    11 TxHeader     c Content-Encoding: gzip
 35    11 TxHeader     c X-Varnish: 1594679620
 36    11 TxHeader     c Via: 1.1 varnish
 37    11 TxHeader     c X-Cache: MISS
 38    11 TxHeader     c host: zh.moegirl.org
 39    11 TxHeader     c Content-Length: 14977
 40    11 TxHeader     c Accept-Ranges: bytes
 41    11 TxHeader     c Date: Wed, 14 May 2014 15:52:33 GMT
 42    11 TxHeader     c X-Varnish: 1750481507 1750481502
 43    11 TxHeader     c Age: 180
 44    11 TxHeader     c Via: 1.1 varnish
 45    11 TxHeader     c Connection: keep-alive
 46    11 TxHeader     c v-Cache: HIT
 47    11 Length       c 14977
 48    11 ReqEnd       c 1750481507 1400082753.326334476
1400082753.326504469 0.000313997 0.000061512 0.000108480



*Varnish Log From Client 2 (192.168.66.106)*

  1    11 SessionOpen  c 192.168.66.106 34154 :80
  2    11 ReqStart     c 192.168.66.106 34154 1750481508
  3    11 RxRequest    c GET
  4    11 RxURL        c /Mainpage
  5    11 RxProtocol   c HTTP/1.1
  6    11 RxHeader     c Host: zh.moegirl.org
  7    11 RxHeader     c Connection: keep-alive
  8    11 RxHeader     c Cache-Control: max-age=0
  9    11 RxHeader     c Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
 10    11 RxHeader     c User-Agent: Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.132 Safari/537.36
 11    11 RxHeader     c Accept-Encoding: gzip,deflate,sdch
 12    11 RxHeader     c Accept-Language:
zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,en-US;q=0.2,en-GB;q=0.2
 13    11 RxHeader     c Cookie:
__gads=ID=b048dccb69e9da93:T=1399163153:S=ALNI_Mao_IUR1acm9tlz_9E4C5DuSDZ98g;
wikiEditor-0-booklet-characters-page=latin; wikiEditor-0-toolbar-
section=advanced; moegirlSSOUserName=Fishthirteen;
moegirlSSO_session=bfmb7k0dadsau1dalp5ou53uc6; moegir
 14    11 VCL_call     c recv lookup
 15    11 VCL_call     c hash
 16    11 Hash         c /Mainpage
 17    11 Hash         c zh.moegirl.org
 18    11 VCL_return   c hash
 19    11 Hit          c 1750481474
 20    11 VCL_call     c hit deliver
 21    11 VCL_call     c deliver deliver
 22    11 TxProtocol   c HTTP/1.1
 23    11 TxStatus     c 200
 24    11 TxResponse   c OK
 25    11 TxHeader     c Server: nginx/1.6.0
 26    11 TxHeader     c Content-Type: text/html; charset=UTF-8
 27    11 TxHeader     c Vary: Accept-Encoding, Accept-Encoding, Cookie,
Accept-Language
 28    11 TxHeader     c X-Content-Type-Options: nosniff
 29    11 TxHeader     c Content-language: zh
 30    11 TxHeader     c Cache-Control: s-maxage=2678400, must-revalidate,
max-age=0
 31    11 TxHeader     c Last-Modified: Mon, 12 May 2014 20:01:11 GMT
 32    11 TxHeader     c Content-Encoding: gzip
 33    11 TxHeader     c X-Varnish: 1594676989
 34    11 TxHeader     c Via: 1.1 varnish
 35    11 TxHeader     c X-Cache: MISS
 36    11 TxHeader     c host: zh.moegirl.org
 37    11 TxHeader     c Content-Length: 14975
 38    11 TxHeader     c Accept-Ranges: bytes
 39    11 TxHeader     c Date: Wed, 14 May 2014 15:53:18 GMT
 40    11 TxHeader     c X-Varnish: 1750481508 1750481474
 41    11 TxHeader     c Age: 514
 42    11 TxHeader     c Via: 1.1 varnish
 43    11 TxHeader     c Connection: keep-alive
 44    11 TxHeader     c v-Cache: HIT
 45    11 Length       c 14975
 46    11 ReqEnd       c 1750481508 1400082798.821015596
1400082798.821227551 0.000247717 0.000054121 0.000157833


*You can see the hash keys are same (**/Mainpage + **zh.moegirl.org
<http://zh.moegirl.org>) but the hit object is different(1750481502 and
1750481474)*


*And following is my default.vcl*.  I just change a little from the default
vcl settings.

backend default {
    .host = "zh.moegirl.org";
    .port = "80";
}
#
# Below is a commented-out copy of the default VCL logic.  If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
 sub vcl_recv {
     if (req.restarts == 0) {
     if (req.http.x-forwarded-for) {
         set req.http.X-Forwarded-For =
         req.http.X-Forwarded-For + ", " + client.ip;
     } else {
         set req.http.X-Forwarded-For = client.ip;
     }


     }
     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.http.Cookie ~ "UserID") {
     } else {
       unset req.http.Cookie;
     }


     return (lookup);
 }

 sub vcl_pipe {
     # Note that only the first request to the backend will have
     # X-Forwarded-For set.  If you use X-Forwarded-For and want to
     # have it set for all requests, make sure to have:
     # set bereq.http.connection = "close";
     # here.  It is not set by default as it might break some broken web
     # applications, like IIS with NTLM authentication.
     return (pipe);
 }

 sub vcl_pass {
     return (pass);
 }

 sub vcl_hash {
     hash_data(req.url);
     if (req.http.host) {
         hash_data(req.http.host);
     } else {
         hash_data(server.ip);
     }

     return (hash);
 }

 sub vcl_hit {
     return (deliver);
 }

 sub vcl_miss {
     return (fetch);
 }

 sub vcl_fetch {

    if (beresp.http.host != req.http.host) {
      set beresp.http.host = req.http.host;
    }


   //set beresp.http.host = "zh.moegirl.org:6081";


     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);
     }
     return (deliver);
 }

 sub vcl_deliver {
   if (obj.hits > 0) {
     set resp.http.v-Cache = "HIT";
   } else {
     set resp.http.v_Cache = "MISS";
   }

     return (deliver);
 }

 sub vcl_error {
     set obj.http.Content-Type = "text/html; charset=utf-8";
     set obj.http.Retry-After = "5";
     synthetic {"
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
   <head>
     <title>"} + obj.status + " " + obj.response + {"</title>
   </head>
   <body>
     <h1>Error "} + obj.status + " " + obj.response + {"</h1>
     <p>"} + obj.response + {"</p>
     <h3>Guru Meditation:</h3>
     <p>XID: "} + req.xid + {"</p>
     <hr>
     <p>Varnish cache server</p>
   </body>
 </html>
 "};
     return (deliver);
 }

 sub vcl_init {
     return (ok);
 }

 sub vcl_fini {
     return (ok);
 }


*And my enviroment*

Varnish Version: 3.0.5
OS: Ubuntu 14.04 LTS
Browers: Chromium 34 (One is in Linux(Debain Testing), and other is in
Windows 8)

Besides, please forgive my pool English.

Thank you very much!

Fish Thirteen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20140515/d71c2f40/attachment.html>


More information about the varnish-misc mailing list