[master] ff73bc4e5 Add counters: beresp_uncacheable, beresp_shortlived

Nils Goroll nils.goroll at uplex.de
Mon Aug 31 13:33:08 UTC 2020


commit ff73bc4e50f34988507c8a8ba89569ecd64895fc
Author: Emanuele Rocca <ema at wikimedia.org>
Date:   Mon Aug 31 10:27:14 2020 +0200

    Add counters: beresp_uncacheable, beresp_shortlived
    
    Uncacheable and shortlived objects end up in transient memory. Add two
    counters to track both type of responses separately.

diff --git a/bin/varnishd/VSC_main.vsc b/bin/varnishd/VSC_main.vsc
index a7cacb7cc..41c2b1228 100644
--- a/bin/varnishd/VSC_main.vsc
+++ b/bin/varnishd/VSC_main.vsc
@@ -137,6 +137,19 @@
 	Count of misses. A cache miss indicates the object was fetched from
 	the backend before delivering it to the client.
 
+.. varnish_vsc:: beresp_uncacheable
+   :group: wrk
+   :oneliner: Uncacheable backend responses
+
+   Count of backend responses considered uncacheable.
+
+.. varnish_vsc:: beresp_shortlived
+   :group: wrk
+   :oneliner: Shortlived objects
+
+   Count of objects created with ttl+grace+keep shorter than the 'shortlived'
+   runtime parameter.
+
 .. varnish_vsc:: backend_conn
 	:oneliner:	Backend conn. success
 
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index ce603e509..1c71e08b4 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -58,8 +58,14 @@ vbf_allocobj(struct busyobj *bo, unsigned l)
 
 	lifetime = oc->ttl + oc->grace + oc->keep;
 
-	if (bo->uncacheable || lifetime < cache_param->shortlived)
+	if (bo->uncacheable) {
 		stv = stv_transient;
+		bo->wrk->stats->beresp_uncacheable++;
+	}
+	else if (lifetime < cache_param->shortlived) {
+		stv = stv_transient;
+		bo->wrk->stats->beresp_shortlived++;
+	}
 	else
 		stv = bo->storage;
 
diff --git a/bin/varnishtest/tests/b00066.vtc b/bin/varnishtest/tests/b00066.vtc
index 7eb286f4b..d1c224e04 100644
--- a/bin/varnishtest/tests/b00066.vtc
+++ b/bin/varnishtest/tests/b00066.vtc
@@ -100,3 +100,5 @@ client c1 {
 
 
 varnish v1 -expect *.s1.req == 12
+varnish v1 -expect beresp_uncacheable == 12
+varnish v1 -expect beresp_shortlived == 0
diff --git a/bin/varnishtest/tests/s00007.vtc b/bin/varnishtest/tests/s00007.vtc
index 39eecf5b2..0374605ab 100644
--- a/bin/varnishtest/tests/s00007.vtc
+++ b/bin/varnishtest/tests/s00007.vtc
@@ -40,3 +40,4 @@ client c1 {
 	expect resp.body == "foo"
 } -run
 
+varnish v1 -expect beresp_shortlived == 1


More information about the varnish-commit mailing list