Commit 05f673a9 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Withdraw backend VSC counters when VCL is cold

parent ab9af460
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
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
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