[master] 05f673a Withdraw backend VSC counters when VCL is cold
Poul-Henning Kamp
phk at FreeBSD.org
Tue Mar 10 10:02:48 CET 2015
commit 05f673a95e0b09053eb454f74b66aab1a251c21f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Mar 10 09:02:29 2015 +0000
Withdraw backend VSC counters when VCL is cold
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index cc3da2e..a02a7d8 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -332,10 +332,22 @@ VRT_event_vbe(VRT_CTX, enum vcl_event_e ev, const struct director *d,
assert(d->priv2 == vrt);
CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
+ if (ev == VCL_EVENT_WARM) {
+ be->vsc = VSM_Alloc(sizeof *be->vsc,
+ VSC_CLASS, VSC_type_vbe, be->display_name);
+ AN(be->vsc);
+ }
+
if (be->probe != NULL && ev == VCL_EVENT_WARM)
VBP_Control(be, 0);
+
if (be->probe != NULL && ev == VCL_EVENT_COLD)
VBP_Control(be, 1);
+
+ if (ev == VCL_EVENT_COLD) {
+ VSM_Free(be->vsc);
+ be->vsc = NULL;
+ }
}
void
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index da22175..e612982 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -66,7 +66,7 @@ VBE_DeleteBackend(struct backend *b)
free(b->ipv4);
free(b->ipv6);
free(b->display_name);
- VSM_Free(b->vsc);
+ AZ(b->vsc);
VBT_Rel(&b->tcp_pool);
Lck_Delete(&b->mtx);
FREE_OBJ(b);
@@ -97,8 +97,6 @@ VBE_AddBackend(const char *vcl, const struct vrt_backend *vb)
bprintf(buf, "%s.%s", vcl, vb->vcl_name);
REPLACE(b->display_name, buf);
- b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_type_vbe, buf);
-
b->vcl_name = vb->vcl_name;
b->ipv4_addr = vb->ipv4_addr;
b->ipv6_addr = vb->ipv6_addr;
diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c
index d4cca48..ee3602b 100644
--- a/bin/varnishd/cache/cache_backend_poll.c
+++ b/bin/varnishd/cache/cache_backend_poll.c
@@ -260,8 +260,10 @@ vbp_has_poked(struct vbp_target *vt)
vt->backend->vcl_name, logmsg, bits,
vt->good, vt->probe.threshold, vt->probe.window,
vt->last, vt->avg, vt->resp_buf);
- if (!vt->disable)
+ if (!vt->disable) {
+ AN(vt->backend->vsc);
vt->backend->vsc->happy = vt->happy;
+ }
}
Lck_Unlock(&vt->mtx);
}
@@ -457,6 +459,7 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p,
b->probe = vt;
VTAILQ_INSERT_TAIL(&vbp_list, vt, list);
Lck_New(&vt->mtx, lck_backend);
+ vt->disable = 1;
vt->tcp_pool = VBT_Ref(b->ipv4, b->ipv6);
AN(vt->tcp_pool);
diff --git a/bin/varnishtest/tests/v00043.vcl b/bin/varnishtest/tests/v00043.vcl
index 17e9798..6e38fe9 100644
--- a/bin/varnishtest/tests/v00043.vcl
+++ b/bin/varnishtest/tests/v00043.vcl
@@ -1,23 +1,56 @@
varnishtest "vcl.state coverage tests"
-server s1 {
+server s1 -repeat 20 {
rxreq
txresp
+ delay .2
+ close
} -start
-varnish v1 -vcl+backend {} -start
-varnish v1 -vcl+backend {}
+varnish v1 -vcl {
+ backend default {
+ .host = "${s1_addr}";
+ .probe = { .interval = 1s; .initial = 1;}
+ }
+} -start
-varnish v1 -cliok "param.set vcl_cooldown 5"
+varnish v1 -cliok "param.set vcl_cooldown 3"
-varnish v1 -cliok "vcl.list"
-varnish v1 -cliok "vcl.use vcl2"
-varnish v1 -cliok "vcl.list"
-delay 5
-varnish v1 -cliok "vcl.list"
-varnish v1 -cliok "vcl.state vcl1 warm"
-varnish v1 -cliok "vcl.list"
+# We only have one vcl yet
+varnish v1 -expect VBE.vcl1.default.happy > 0
+varnish v1 -expect !VBE.vcl2.default.happy
+varnish v1 -cliok "backend.list -p *.*"
+
+varnish v1 -vcl {
+ backend default {
+ .host = "${s1_addr}";
+ .probe = { .interval = 1s; .initial = 1;}
+ }
+}
+
+# Now we have two vcls (and run on the latest loaded)
+varnish v1 -expect VBE.vcl1.default.happy > 0
+varnish v1 -expect VBE.vcl2.default.happy > 0
+
+# Freeze the first VCL
+varnish v1 -cliok "vcl.state vcl1 cold"
+varnish v1 -expect !VBE.vcl1.default.happy
+
+# Set it auto should be a no-op
+varnish v1 -cliok "vcl.state vcl1 auto"
+varnish v1 -expect !VBE.vcl1.default.happy
+
+# Use it, and it should come alive
varnish v1 -cliok "vcl.use vcl1"
+varnish v1 -expect VBE.vcl1.default.happy > 0
+varnish v1 -expect VBE.vcl2.default.happy > 0
+
+# and the unused one should go cold
+delay 4
+varnish v1 -expect !VBE.vcl2.default.happy
+
+# Mark the used warm and use it the other
+varnish v1 -cliok "vcl.state vcl1 warm"
varnish v1 -cliok "vcl.use vcl2"
-delay 5
-varnish v1 -cliok "vcl.list"
+delay 4
+varnish v1 -expect VBE.vcl2.default.happy > 0
More information about the varnish-commit
mailing list