Commit 1d62f5da authored by Pål Hermunn Johansen's avatar Pål Hermunn Johansen

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).
parent 222ad8c3
......@@ -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.
......
......@@ -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:
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment