[experimental-ims] fa3b136 Ensure ban lurker sleeps 1.0s on failure

Geoff Simmons geoff at varnish-cache.org
Mon Jan 9 21:52:24 CET 2012


commit fa3b136f2169a71b63603835c69441ca37913507
Author: Kristian Lyngstol <kristian at bohemians.org>
Date:   Mon Oct 17 14:09:11 2011 +0200

    Ensure ban lurker sleeps 1.0s on failure
    
    As per documentation, the ban lurker sleeps ban_lurker_sleep when it is
    successful, but on failure it should only sleep 1.0s. No point hammering
    the ban list every 0.01s if bans aren't even used.
    
    Fixes #1030

diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c
index 736cbf7..5b7d457 100644
--- a/bin/varnishd/cache_ban.c
+++ b/bin/varnishd/cache_ban.c
@@ -754,7 +754,7 @@ BAN_CheckObject(struct object *o, const struct sess *sp)
  * Ban tail lurker thread
  */
 
-static void
+static int
 ban_lurker_work(const struct sess *sp)
 {
 	struct ban *b, *bf;
@@ -773,21 +773,21 @@ ban_lurker_work(const struct sess *sp)
 	if (bf != NULL) {
 		Lck_Unlock(&ban_mtx);
 		BAN_Free(bf);
-		return;
+		return (0);
 	}
 
 	/* Find the last ban give up, if we have only one */
 	b = VTAILQ_LAST(&ban_head, banhead_s);
 	if (b == ban_start) {
 		Lck_Unlock(&ban_mtx);
-		return;
+		return (0);
 	}
 
 	/* Find the first object on it, if any */
 	oc = VTAILQ_FIRST(&b->objcore);
 	if (oc == NULL) {
 		Lck_Unlock(&ban_mtx);
-		return;
+		return (0);
 	}
 
 	/* Try to lock the objhead */
@@ -795,7 +795,7 @@ ban_lurker_work(const struct sess *sp)
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 	if (Lck_Trylock(&oh->mtx)) {
 		Lck_Unlock(&ban_mtx);
-		return;
+		return (0);
 	}
 
 	/*
@@ -808,7 +808,7 @@ ban_lurker_work(const struct sess *sp)
 	if (oc2 == NULL) {
 		Lck_Unlock(&oh->mtx);
 		Lck_Unlock(&ban_mtx);
-		return;
+		return (0);
 	}
 	/*
 	 * Grab a reference to the OC and we can let go of the BAN mutex
@@ -825,12 +825,13 @@ ban_lurker_work(const struct sess *sp)
 	Lck_Unlock(&oh->mtx);
 	WSP(sp, SLT_Debug, "lurker: %p %g %d", oc, o->exp.ttl, i);
 	(void)HSH_Deref(sp->wrk, NULL, &o);
+	return (i);
 }
 
 static void * __match_proto__(bgthread_t)
 ban_lurker(struct sess *sp, void *priv)
 {
-
+	int i = 0;
 	(void)priv;
 	while (1) {
 		if (params->ban_lurker_sleep == 0.0) {
@@ -838,8 +839,11 @@ ban_lurker(struct sess *sp, void *priv)
 			VTIM_sleep(1.0);
 			continue;
 		}
-		VTIM_sleep(params->ban_lurker_sleep);
-		ban_lurker_work(sp);
+		if (i != 0)
+			VTIM_sleep(params->ban_lurker_sleep);
+		else
+			VTIM_sleep(1.0);
+		i = ban_lurker_work(sp);
 		WSL_Flush(sp->wrk, 0);
 		WRK_SumStat(sp->wrk);
 	}
diff --git a/bin/varnishtest/tests/r01030.vtc b/bin/varnishtest/tests/r01030.vtc
new file mode 100644
index 0000000..97ef3d7
--- /dev/null
+++ b/bin/varnishtest/tests/r01030.vtc
@@ -0,0 +1,64 @@
+varnishtest "Test ban_lurker_sleep vs failed ban lurker"
+
+# The idea here is that the ban lurker should always wait 1 second when it
+# can't proceed, as per documentation and original intent. The
+# ban_lurker_sleep should not affect sleep-times when the lurker fails.
+
+server s1 {
+	rxreq
+	txresp -status 200
+
+	rxreq
+	txresp -status 200
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		if (req.request == "BAN") {
+			ban("obj.http.url ~ /");
+			error 201 "banned";
+		}
+		return (lookup);
+	}
+	sub vcl_fetch {
+		set beresp.http.url = req.url;
+	}
+} -start
+
+varnish v1 -cliok "param.set ban_lurker_sleep 0.01"
+varnish v1 -expect n_ban_obj_test == 0
+
+delay 0.01
+client c1 {
+	txreq -req GET
+	rxresp
+	expect resp.status == 200
+
+	txreq -req BAN
+	rxresp
+	expect resp.status == 201
+} -run
+
+delay 0.1
+varnish v1 -expect n_ban_obj_test == 0
+
+delay 1.0
+varnish v1 -expect n_ban_obj_test == 1
+
+varnish v1 -cliok "param.set ban_lurker_sleep 5.01"
+
+client c2 {
+	txreq -req GET
+	rxresp
+	expect resp.status == 200
+
+	txreq -req BAN
+	rxresp
+	expect resp.status == 201
+} -run
+
+delay 0.1
+varnish v1 -expect n_ban_obj_test == 1
+
+delay 1.1
+varnish v1 -expect n_ban_obj_test == 2



More information about the varnish-commit mailing list