pages are missing in cache

Tim Dunphy bluethundr at gmail.com
Sun Jun 29 02:51:06 CEST 2014


Hey guys,


 I've setup varnish cache on my site. And I'm using this command to
determine which pages are not being cached:

varnishtop -b -i TxURL

 It seems that the following list (and then some) are all cache misses if
what I'm reading is to be believed:

list length 150

     6.97 TxURL          /cometchat/cometchat_receive.php
     3.57 TxURL          /
     0.55 TxURL          /server-status?auto
     0.44 TxURL          /registration.php
     0.44 TxURL          /lightbox/css/lightbox.css
     0.44 TxURL          /css/main_style.css
     0.44 TxURL          /js/jquery-1.7.2.min.js
     0.44 TxURL          /lightbox/js/lightbox.js
     0.41 TxURL          /cometchat/cometchatcss.php
     0.41 TxURL          /cometchat/cometchatjs.php
     0.41 TxURL          /images/img_fireit.jpg
     0.41 TxURL          /images/logo.png
     0.41 TxURL          /images/mainmenu_selectbg.png
     0.41 TxURL          /images/mainmenubg.png
     0.41 TxURL          /images/topmenu_divider.jpg
     0.41 TxURL          /images/headerblockbg.jpg
     0.41 TxURL          /images/icon_join.png
     0.41 TxURL          /images/icon_comments.png
     0.41 TxURL          /images/bg_viewcount.png
     0.41 TxURL          /cometchat/swf/sound.swf
     0.41 TxURL          /images/icon_twitter2.png
     0.41 TxURL          /images/icon_write.png
     0.59 TxURL
 /joke_details.php?o=o&joke_id=id255111111111111111111111111


I'm just hoping if I present my VCL I can get some pointers on how I can
improve my cache hit ratio. I'm sorry if I'm too much of a newb at this to
be able to zero in on the most relevant parts of the VCL.

# man page for details on VCL syntax and semantics.
#
# Default backend definition.  Set this to point to your content
# server.
#

probe index {
  .url = "/index.php";
  .timeout = 5s;
  .interval = 2s;
  .window = 5;
  .threshold = 3;
}

backend web1  {
  .host = "10.10.10.94";
  .port = "80";
  .probe = index;
  .connect_timeout = 30s;
  .first_byte_timeout = 30s;
  .between_bytes_timeout = 30s;
  .max_connections = 70;
}


director www client {
  { .backend = web1 ; .weight = 2;  }
 }



acl purge {
    "localhost";
    "127.0.0.1";
    "10.10.10.115";
}

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-Forward-For = client.ip;
       }
    }

    set client.identity = req.http.cookie;

    if (req.request != "GET"&&req.request != "HEAD") {
      return (pass);
    }

    if (req.url ~
     "\.(png|gif|jpeg|jpg|ico|swf|css|js|txt|xml)"
      || req.url ~ "/static/"
      || req.url ~ "/userimages/"
      || req.url ~ “/admin/“
      || req.url ~ "/rockmongo/"
      || req.url ~ "/images/") {
      unset req.http.cookie;
      }

      if (req.url ~
      "\.(conf|log|old|properties|tar|war)$") {
        error 403 "Forbidden";
      }

     if (req.url ~ "^/healthcheck.php") { return(pass); }

     if (req.request == "PURGE") {
        if (!client.ip ~ purge) {
            error 405 "Not allowed.";
        }
        return (lookup);
    }

     if (req.backend.healthy) {
                set req.grace = 30s;
        } else {
                set req.grace = 24h;
       }

       # Do not allow outside access to cron.php or install.php.
       if (req.url ~ "^/(cron|install)\.php$") {
       # Have Varnish throw the error directly.
       error 404 "Page not found.";
       }

      if (req.restarts == 0) {
       #Try the directory first.
       set req.backend = www;
      } else if (req.restarts == 1) {
       # Director has failed and we will try the backend web1.
       set req.backend = web1;
       } /*else if (req.restarts == 2) {
       # Director has failed and we will try the backend web1.
            set req.backend = web2;
       } */  else {
        # All back end servers have failed. Go to error page.
         error 503 "Service unavailable";
       }

      return(lookup);

}

sub vcl_error {
  if ( obj.status == 503 ) {
     set obj.http.Content-Type = "text/html; charset=utf-8";
     set obj.http.Retry-After = "5";
     synthetic {"
<html>
<head>
  <title>Page Unavailable</title>
  <style>
    body { background: #303030; text-align: center; color: white; }
    page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0;
padding: 30px; background: #323232; }
       a, a:link, a:visited { color: #CCC; }
       .error { color: #222; }
      </style>
    </head>
    <body onload="setTimeout(function() { window.location = '/' }, 5000)">
    <div id="page">
    <h1 class="title">Page Unavailable</h1>
    <p>The page you requested is temporarily unavailable.</p>
    <p>We're redirecting you to the <a href="/">homepage</a> in 5
seconds.</p>
    <div class="error">(Error "} + obj.status + " " + obj.response +
{")</div>
    </div>
    </body>
     </html>
    "};
 }
}

   sub vcl_hash {
     hash_data(req.url);
     if (req.http.host) {
       set req.http.host =
     regsub(req.http.host,"^beta\.jokefire\.com$", "beta.jokefire.com");
       hash_data(req.http.host);
     } else {
      hash_data(server.ip);
     }

     hash_data(req.url);
     if (req.http.host) {
       set req.http.host =
     regsub(req.http.host,"^ref\.jokefire\.com$", "ref.jokefire.com");
       hash_data(req.http.host);
     } else {
      hash_data(server.ip);
     }

     if (req.url ~ "\.(html|htm)(\?[a-z0-9=]+)?$") {
       set req.http.X-HASH = regsub(req.http.X-HASH,
      "^/.*__", "/__");
     }
     hash_data(req.http.X-HASH);

     return (hash);
    }

   sub vcl_pass {
     return (pass);
    }

    sub vcl_pipe {
      set bereq.http.connection = "close";
      return (pipe);
    }

    sub vcl_fetch {

          if ( req.url ~ "\.(png|jpg|gif)$") {
   set beresp.ttl = 1w;
           unset beresp.http.Set-Cookie;
          }

         if ( req.url ~ "\.(css|js)$") {
           set beresp.ttl = 1h;
           unset beresp.http.Set-Cookie;

         }

         if ( req.url ~ "\.(html)$") {
           set beresp.ttl = 15m;
           unset beresp.http.Set-Cookie;
          }

          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);
         }

        if ( req.url ~ "/static/") {
          set beresp.ttl = 30m;
           unset beresp.http.set-cookie;
         }

        if ( beresp.status>= 500 && req.request != "POST") {
              return(restart);
         }

   }


    sub vcl_deliver {
     if (obj.hits> 0) {
      set resp.http.X-Cache = "HIT";
     } else {
        set resp.http.X-Cache = "MISS";
     }
     unset resp.http.Server;
     unset resp.http.Via;
     unset resp.http.Age;
     unset resp.http.X-Varnish;
     return (deliver);
 }


Thanks for any advice you may have!

Tim

-- 
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20140628/c72dc115/attachment.html>


More information about the varnish-misc mailing list