0

I've set up apache and Varnish, no particular configuration involved (apache on 8080, varnish serving pages at port 80). I also dropped cookies in Varnish to ensure maximum caching of Wordpress sites.

The website works, it loads etc.; but it seems that Varnish doesn't cache anything. When I open Varnishstat, I see always Hitrate ratio: 0; and lots of "inf backend_busy" "inf backend_reuse" etc.; and no accepted_connections. Here's a sample:

0+00:00:00
Hitrate ratio:        0        0        0
Hitrate avg:     0.0000   0.0000   0.0000

         146         0.00          inf backend_busy - Backend conn. too many
         164         0.00          inf backend_reuse - Backend conn. reuses
          16         0.00          inf backend_toolate - Backend conn. was closed
         101         0.00          inf backend_recycle - Backend conn. recycles
          47         0.00          inf backend_retry - Backend conn. retry
         111         0.00          inf fetch_head - Fetch head

How come?

UPDATE: a Varnishlog:

        0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712509 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712512 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712515 1.0
   13 BackendClose - default
   13 BackendOpen  b default 127.0.0.1 38776 127.0.0.1 8080
   13 BackendXID   b 1420058564
   13 TxRequest    b GET
   13 TxURL        b /
   13 TxProtocol   b HTTP/1.1
   13 TxHeader     b Host: www.test-mystreaming.it
   13 TxHeader     b Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
   13 TxHeader     b User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
   13 TxHeader     b Accept-Language: en-US,en;q=0.8,it-IT;q=0.6,it;q=0.4
   13 TxHeader     b X-Forwarded-For: 2.229.61.20
   13 TxHeader     b X-Varnish: 1420058564
   13 TxHeader     b Accept-Encoding: gzip
   13 RxProtocol   b HTTP/1.1
   13 RxStatus     b 200
   13 RxResponse   b OK
   13 RxHeader     b Date: Thu, 13 Mar 2014 12:08:37 GMT
   13 RxHeader     b Server: Apache/2.2.22 (Ubuntu)
   13 RxHeader     b X-Powered-By: PHP/5.3.10-1ubuntu3.10
   13 RxHeader     b X-Pingback: http://www.test-mystreaming.it/xmlrpc.php
   13 RxHeader     b Vary: Accept-Encoding
   13 RxHeader     b Content-Encoding: gzip
   13 RxHeader     b Content-Length: 7682
   13 RxHeader     b Content-Type: text/html; charset=UTF-8
   13 Fetch_Body   b 4(length) cls 0 mklen 1
   13 Length       b 7682
   13 BackendReuse b default
   11 SessionOpen  c 2.229.61.20 56012 :80
   11 ReqStart     c 2.229.61.20 56012 1420058564
   11 RxRequest    c GET
   11 RxURL        c /
   11 RxProtocol   c HTTP/1.1
   11 RxHeader     c Host: www.test-mystreaming.it
   11 RxHeader     c Connection: keep-alive
   11 RxHeader     c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
   11 RxHeader     c User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
   11 RxHeader     c Accept-Encoding: gzip,deflate,sdch
   11 RxHeader     c Accept-Language: en-US,en;q=0.8,it-IT;q=0.6,it;q=0.4
   11 RxHeader     c Cookie: wp-settings-1=m5%3Do%26m4%3Do%26hidetb%3D1%26m9%3Do%26m1%3Do%26imgsize%3Dfull%26editor%3Dhtml%26libraryContent%3Dbrowse; wp-settings-time-1=1394014590; _xyz_lbx_until=1; _xyz_lbx_pc=1; __utma=257699214.1231191244.1394014450.1394039099.1394709725.5
   11 VCL_call     c recv lookup
   11 VCL_call     c hash
   11 Hash         c /
   11 Hash         c www.test-mystreaming.it
   11 VCL_return   c hash
   11 VCL_call     c miss fetch
   11 Backend      c 13 default default
   11 TTL          c 1420058564 RFC 120 -1 -1 1394712518 0 1394712517 0 0
   11 VCL_call     c fetch deliver
   11 ObjProtocol  c HTTP/1.1
   11 ObjResponse  c OK
   11 ObjHeader    c Date: Thu, 13 Mar 2014 12:08:37 GMT
   11 ObjHeader    c Server: Apache/2.2.22 (Ubuntu)
   11 ObjHeader    c X-Powered-By: PHP/5.3.10-1ubuntu3.10
   11 ObjHeader    c X-Pingback: http://www.test-mystreaming.it/xmlrpc.php
   11 ObjHeader    c Vary: Accept-Encoding
   11 ObjHeader    c Content-Encoding: gzip
   11 ObjHeader    c Content-Type: text/html; charset=UTF-8
   11 Gzip         c u F - 7682 33861 80 80 61389
   11 VCL_call     c deliver deliver
   11 TxProtocol   c HTTP/1.1
   11 TxStatus     c 200
   11 TxResponse   c OK
   11 TxHeader     c Server: Apache/2.2.22 (Ubuntu)
   11 TxHeader     c X-Powered-By: PHP/5.3.10-1ubuntu3.10
   11 TxHeader     c X-Pingback: http://www.test-mystreaming.it/xmlrpc.php
   11 TxHeader     c Vary: Accept-Encoding
   11 TxHeader     c Content-Encoding: gzip
   11 TxHeader     c Content-Type: text/html; charset=UTF-8
   11 TxHeader     c Content-Length: 7682
   11 TxHeader     c Accept-Ranges: bytes
   11 TxHeader     c Date: Thu, 13 Mar 2014 12:08:38 GMT
   11 TxHeader     c X-Varnish: 1420058564
   11 TxHeader     c Age: 0
   11 TxHeader     c Via: 1.1 varnish
   11 TxHeader     c Connection: keep-alive
   11 Length       c 7682
   11 ReqEnd       c 1420058564 1394712517.488089323 1394712518.017520905 0.000098944 0.529357433 0.000074148
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712518 1.0
    0 CLI          - Rd ping
    0 CLI          - Wr 200 19 PONG 1394712521 1.0
  • What do the Apache logs say? Varnish logs? Doesn't look like enough information provided to answer. – Sam Halicke Mar 13 '14 at 11:59
  • I added an extract of a Varnish log, what else can I provide? – Carmine Giangregorio Mar 13 '14 at 12:08
  • Can you post your vcl? – Kirrus Mar 14 '14 at 18:28
  • Here's my default.vcl: pastebin.com/z7JKztj7 – Carmine Giangregorio Mar 19 '14 at 14:02
1

To determine if the responses are cacheable, please add the following to your VCL, and update your question with varnishlog output after the change. Also please post your varnish command line, especially the default TTL (-t parameter). Since your backend server is not sending a Cache-Control header, and you are not defining beresp.ttl in vcl_fetch, Varnish is using the default value for TTL defined using the -t switch.

The following VCL will add X-Cacheable and X-ttl headers to each request.

sub vcl_fetch {

  # Varnish determined the object was not cacheable
  if (!(beresp.ttl > 0s)) {
    set beresp.http.X-Cacheable = "NO:Not Cacheable, ttl <0s";
    set beresp.http.X-ttl = beresp.ttl;
    return(hit_for_pass);
  }
  elseif (req.http.Cookie) {
    set beresp.http.X-Cacheable = "NO:Got cookie";
    set beresp.http.X-Cookie = req.http.Cookie;
    return(hit_for_pass);
  }
  elseif (beresp.http.Cache-Control ~ "private") {
    set beresp.http.X-Cacheable = "NO:Cache-Control=private";
    return(hit_for_pass);
  }
  elseif (beresp.http.Cache-Control ~ "no-cache" || beresp.http.Pragma ~ "no-cache") {
    set beresp.http.X-Cacheable = "Refetch forced by user";
    return(hit_for_pass);
  # You are extending the lifetime of the object artificially
  }
  elseif (beresp.ttl < 1s) {
    set beresp.ttl   = 5s;
    set beresp.grace = 5s;
    set beresp.http.X-Cacheable = "YES:FORCED";
  # Varnish determined the object was cacheable
  } else {
    set beresp.http.X-Cacheable = "YES";
    set beresp.http.X-ttl = beresp.ttl;
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.