<div dir="ltr"><div>Hey guys,</div><div><br></div><div><br></div><div> I've setup varnish cache on my site. And I'm using this command to determine which pages are not being cached:</div><div><br></div><div>varnishtop -b -i TxURL<br>
</div><div><br></div><div> It seems that the following list (and then some) are all cache misses if what I'm reading is to be believed:</div><div><br></div><div>list length 150</div><div><br></div><div> 6.97 TxURL /cometchat/cometchat_receive.php</div>
<div> 3.57 TxURL /</div><div> 0.55 TxURL /server-status?auto</div><div> 0.44 TxURL /registration.php</div><div> 0.44 TxURL /lightbox/css/lightbox.css</div><div> 0.44 TxURL /css/main_style.css</div>
<div> 0.44 TxURL /js/jquery-1.7.2.min.js</div><div> 0.44 TxURL /lightbox/js/lightbox.js</div><div> 0.41 TxURL /cometchat/cometchatcss.php</div><div> 0.41 TxURL /cometchat/cometchatjs.php</div>
<div> 0.41 TxURL /images/img_fireit.jpg</div><div> 0.41 TxURL /images/logo.png</div><div> 0.41 TxURL /images/mainmenu_selectbg.png</div><div> 0.41 TxURL /images/mainmenubg.png</div>
<div> 0.41 TxURL /images/topmenu_divider.jpg</div><div> 0.41 TxURL /images/headerblockbg.jpg</div><div> 0.41 TxURL /images/icon_join.png</div><div> 0.41 TxURL /images/icon_comments.png</div>
<div> 0.41 TxURL /images/bg_viewcount.png</div><div> 0.41 TxURL /cometchat/swf/sound.swf</div><div> 0.41 TxURL /images/icon_twitter2.png</div><div> 0.41 TxURL /images/icon_write.png</div>
<div> 0.59 TxURL /joke_details.php?o=o&joke_id=id255111111111111111111111111</div><div><br></div><div><br></div><div>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.</div>
<div><br></div><div><div># man page for details on VCL syntax and semantics.</div><div># </div><div># Default backend definition. Set this to point to your content</div><div># server.</div><div># </div><div><br></div><div>
probe index {</div><div> .url = "/index.php";</div><div> .timeout = 5s;</div><div> .interval = 2s;</div><div> .window = 5;</div><div> .threshold = 3;</div><div>}</div><div><br></div><div>backend web1 {</div>
<div> .host = "10.10.10.94";</div><div> .port = "80";</div><div> .probe = index; </div><div> .connect_timeout = 30s;</div><div> .first_byte_timeout = 30s;</div><div> .between_bytes_timeout = 30s;</div>
<div> .max_connections = 70;</div><div>}</div><div><br></div><div><br></div><div>director www client {</div><div> { .backend = web1 ; .weight = 2; }</div><div> }</div><div><br></div><div><br></div><div><br></div><div>acl purge {</div>
<div> "localhost";</div><div> "127.0.0.1";</div><div> "10.10.10.115";</div><div>}</div><div><br></div><div>sub vcl_recv {</div><div><br></div><div> if (req.restarts == 0) {</div><div>
if (req.http.x-forwarded-for) </div><div> { </div><div> set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;</div><div> } else {</div><div> set req.http.X-Forward-For = client.ip; </div>
<div> }</div><div> }</div><div> </div><div> set client.identity = req.http.cookie;</div><div> </div><div> if (req.request != "GET"&&req.request != "HEAD") { </div><div> return (pass); </div>
<div> }</div><div> </div><div> if (req.url ~ </div><div> "\.(png|gif|jpeg|jpg|ico|swf|css|js|txt|xml)"</div><div> || req.url ~ "/static/" </div><div> || req.url ~ "/userimages/"</div>
<div> || req.url ~ “/admin/“</div><div> || req.url ~ "/rockmongo/" </div><div> || req.url ~ "/images/") {</div><div> unset req.http.cookie; </div><div> } </div><div> </div>
<div> if (req.url ~</div><div> "\.(conf|log|old|properties|tar|war)$") {</div><div> error 403 "Forbidden";</div><div> }</div><div><br></div><div> if (req.url ~ "^/healthcheck.php") { return(pass); }</div>
<div><br></div><div> if (req.request == "PURGE") {</div><div> if (!client.ip ~ purge) {</div><div> error 405 "Not allowed.";</div><div> }</div><div> return (lookup);</div>
<div> }</div><div><br></div><div> if (req.backend.healthy) {</div><div> set req.grace = 30s;</div><div> } else {</div><div> set req.grace = 24h;</div><div> }</div><div><br>
</div><div> # Do not allow outside access to cron.php or install.php.</div><div> if (req.url ~ "^/(cron|install)\.php$") {</div><div> # Have Varnish throw the error directly.</div><div> error 404 "Page not found.";</div>
<div> }</div><div><br></div><div> if (req.restarts == 0) {</div><div> #Try the directory first.</div><div> set req.backend = www;</div><div> } else if (req.restarts == 1) {</div><div> # Director has failed and we will try the backend web1.</div>
<div> set req.backend = web1;</div><div> } /*else if (req.restarts == 2) {</div><div> # Director has failed and we will try the backend web1.</div><div> set req.backend = web2;</div><div> } */ else {</div>
<div> # All back end servers have failed. Go to error page.</div><div> error 503 "Service unavailable";</div><div> }</div><div><br></div><div> return(lookup);</div><div> </div><div>}</div>
<div><br></div><div>sub vcl_error {</div><div> if ( obj.status == 503 ) {</div><div> set obj.http.Content-Type = "text/html; charset=utf-8";</div><div> set obj.http.Retry-After = "5";</div><div>
synthetic {"</div><div><html></div><div><head></div><div> <title>Page Unavailable</title></div><div> <style></div><div> body { background: #303030; text-align: center; color: white; }</div>
<div> page { border: 1px solid #CCC; width: 500px; margin: 100px auto 0; padding: 30px; background: #323232; }</div><div> a, a:link, a:visited { color: #CCC; }</div><div> .error { color: #222; }</div><div> </style></div>
<div> </head></div><div> <body onload="setTimeout(function() { window.location = '/' }, 5000)"></div><div> <div id="page"></div><div> <h1 class="title">Page Unavailable</h1></div>
<div> <p>The page you requested is temporarily unavailable.</p></div><div> <p>We're redirecting you to the <a href="/">homepage</a> in 5 seconds.</p></div><div> <div class="error">(Error "} + obj.status + " " + obj.response + {")</div></div>
<div> </div></div><div> </body></div><div> </html></div><div> "};</div><div> }</div><div>}</div><div><br></div><div> sub vcl_hash {</div><div> hash_data(req.url);</div><div> if (req.http.host) {</div>
<div> set req.http.host = </div><div> regsub(req.http.host,"^beta\.jokefire\.com$", "<a href="http://beta.jokefire.com">beta.jokefire.com</a>");</div><div> hash_data(req.http.host);</div>
<div> } else {</div><div> hash_data(server.ip);</div><div> }</div><div><br></div><div> hash_data(req.url);</div><div> if (req.http.host) {</div><div> set req.http.host =</div><div> regsub(req.http.host,"^ref\.jokefire\.com$", "<a href="http://ref.jokefire.com">ref.jokefire.com</a>");</div>
<div> hash_data(req.http.host);</div><div> } else {</div><div> hash_data(server.ip);</div><div> }</div><div><br></div><div> if (req.url ~ "\.(html|htm)(\?[a-z0-9=]+)?$") {</div><div> set req.http.X-HASH = regsub(req.http.X-HASH,</div>
<div> "^/.*__", "/__");</div><div> } </div><div> hash_data(req.http.X-HASH);</div><div><br></div><div> return (hash);</div><div> }</div><div><br></div><div> sub vcl_pass {</div><div>
return (pass);</div><div> }</div><div><br></div><div> sub vcl_pipe {</div><div> set bereq.http.connection = "close"; </div><div> return (pipe);</div><div> }</div><div><br></div><div> sub vcl_fetch {</div>
<div><br></div><div> if ( req.url ~ "\.(png|jpg|gif)$") {</div><div><span class="" style="white-space:pre"> </span> set beresp.ttl = 1w;</div><div> unset beresp.http.Set-Cookie;</div><div> }</div>
<div><br></div><div> if ( req.url ~ "\.(css|js)$") {</div><div> set beresp.ttl = 1h;</div><div> unset beresp.http.Set-Cookie;</div><div><br></div><div> }</div><div><br></div><div>
if ( req.url ~ "\.(html)$") {</div><div> set beresp.ttl = 15m;</div><div> unset beresp.http.Set-Cookie;</div><div> }</div><div><br></div><div> if (beresp.ttl <= 0s ||</div>
<div> beresp.http.Set-Cookie ||</div><div> beresp.http.Vary == "*") {</div><div> /* Mark as "Hit-For-Pass" for the next 2 minutes */</div><div> set beresp.ttl = 120 s;</div>
<div> return (hit_for_pass);</div><div> }</div><div><br></div><div> if ( req.url ~ "/static/") {</div><div> set beresp.ttl = 30m;</div><div> unset beresp.http.set-cookie;</div>
<div> }</div><div><br></div><div> if ( beresp.status>= 500 && req.request != "POST") {</div><div> return(restart);</div><div> }</div><div><br></div><div> }</div><div>
<br></div><div><br></div><div> sub vcl_deliver {</div><div> if (obj.hits> 0) {</div><div> set resp.http.X-Cache = "HIT";</div><div> } else {</div><div> set resp.http.X-Cache = "MISS"; </div>
<div> }</div><div> unset resp.http.Server;</div><div> unset resp.http.Via;</div><div> unset resp.http.Age;</div><div> unset resp.http.X-Varnish;</div><div> return (deliver);</div><div> }</div></div>
<div><br></div><div><br></div><div>Thanks for any advice you may have!</div><div><br></div><div>Tim</div><div><br></div>-- <br>GPG me!!<br><br>gpg --keyserver <a href="http://pool.sks-keyservers.net" target="_blank">pool.sks-keyservers.net</a> --recv-keys F186197B<br>
<br>
</div>