[4.1] a33bf52 Add cache_hit_grace counter

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Thu Nov 30 09:59:07 UTC 2017


commit a33bf527ee50f46320f6f651bcbf6e6605224da5
Author: Pål Hermunn Johansen <hermunn at varnish-software.com>
Date:   Thu Nov 30 10:46:40 2017 +0100

    Add cache_hit_grace counter
    
    The counter cache_hit_grace counts the number of grace hits. To be
    precise, it counts the number of times lookup returns an expired
    object, but vcl_hit is called and decides to return(deliver).
    
    Every time cache_hit_grace is incremented, cache_hit is also
    incremented (so this commit does not change the cache_hit counter).
    
    This is a back port of 1d62f5da43a245966faff82f3ee3e6cff46db0f2.

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index ca6e316..a6c4c0b 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -437,6 +437,8 @@ cnt_lookup(struct worker *wrk, struct req *req)
 		}
 		wrk->stats->cache_hit++;
 		req->is_hit = 1;
+		if (lr == HSH_EXP || lr == HSH_EXPBUSY)
+			wrk->stats->cache_hit_grace++;
 		req->req_step = R_STP_DELIVER;
 		return (REQ_FSM_MORE);
 	case VCL_RET_FETCH:
diff --git a/bin/varnishtest/tests/b00052.vtc b/bin/varnishtest/tests/b00052.vtc
new file mode 100644
index 0000000..23cfcf5
--- /dev/null
+++ b/bin/varnishtest/tests/b00052.vtc
@@ -0,0 +1,52 @@
+varnishtest "The cache_hit_grace counter"
+
+server s1 {
+	# normal fetch
+	rxreq
+	expect req.url == "/1"
+	txresp -hdr "Age: 1" -hdr "Cache-Control: max-age=2" -body "1"
+
+	# background fetch:
+	rxreq
+	expect req.url == "/1"
+	txresp -body "2"
+
+	# normal fetch
+	rxreq
+	expect req.url == "/2"
+	txresp
+} -start
+
+varnish v1 -vcl+backend { } -start
+
+client c1 {
+	txreq -url "/1"
+	rxresp
+	expect resp.body == "1"
+} -run
+
+delay 2
+
+# Get a grace hit, will trigger a background fetch
+
+client c2 {
+	txreq -url "/1"
+	rxresp
+	expect resp.body == "1"
+} -run
+
+delay 2
+
+client c3 {
+	txreq -url "/2"
+	rxresp
+	txreq -url "/1"
+	rxresp
+	expect resp.body == "2"
+} -run
+
+# Check that counters are correct:
+
+varnish v1 -expect cache_hit == 2
+varnish v1 -expect cache_hit_grace == 1
+varnish v1 -expect cache_miss == 2
diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h
index c3b53bd..0da1989 100644
--- a/include/tbl/vsc_f_main.h
+++ b/include/tbl/vsc_f_main.h
@@ -89,6 +89,13 @@ VSC_F(cache_hit,		uint64_t, 1, 'c', 'i', info,
 	"  client without fetching it from a backend server."
 )
 
+VSC_F(cache_hit_grace,		uint64_t, 1, 'c', 'i', info,
+    "Cache grace hits",
+	"Count of cache hits with grace. A cache hit with grace is a cache"
+	" hit where the object is expired. Note that such hits are also"
+	" ncluded in the cache_hit counter."
+)
+
 VSC_F(cache_hitpass,		uint64_t, 1, 'c', 'i', info,
     "Cache hits for pass",
 	"Count of hits for pass"


More information about the varnish-commit mailing list