[master] 1d62f5d Add cache_hit_grace counter
PÃ¥l Hermunn Johansen
hermunn at varnish-software.com
Fri Nov 17 12:58:09 UTC 2017
commit 1d62f5da43a245966faff82f3ee3e6cff46db0f2
Author: Pål Hermunn Johansen <hermunn at varnish-software.com>
Date: Fri Nov 17 13:47:28 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).
diff --git a/bin/varnishd/VSC_main.vsc b/bin/varnishd/VSC_main.vsc
index ca999f7..f303453 100644
--- a/bin/varnishd/VSC_main.vsc
+++ b/bin/varnishd/VSC_main.vsc
@@ -56,6 +56,13 @@
Count of cache hits. A cache hit indicates that an object has been
delivered to a client without fetching it from a backend server.
+.. varnish_vsc:: cache_hit_grace
+ :oneliner: 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
+ included in the cache_hit counter.
+
.. varnish_vsc:: cache_hitpass
:oneliner: Cache hits for pass.
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 95dafbd..8e9b019 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -523,6 +523,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_MISS:
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
More information about the varnish-commit
mailing list