[master] 61ade8c Change the way the pacing of the ban-lurker is configured.

Poul-Henning Kamp phk at FreeBSD.org
Fri Dec 13 12:15:30 CET 2013


commit 61ade8c8e583f0781f8dea72ad726ae758077921
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Dec 13 11:12:17 2013 +0000

    Change the way the pacing of the ban-lurker is configured.
    
    A new parameter, $ban_lurker_age, sets a minimum age bans must
    have before the lurker will touch them.  This way the lurker
    stays out of the "rush" that happens right after a ban has been
    added.
    
    Another new parameter, $ban_lurker_batch, determines how many
    objects the lurker will examine, before it takes a $ban_lurker_sleep
    in order to not monopolize CPU.

diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 25274fd..426faa7 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -135,6 +135,7 @@ static pthread_t ban_thread;
 static struct ban * volatile ban_start;
 static struct objcore oc_marker = { .magic = OBJCORE_MAGIC, };
 static bgthread_t ban_lurker;
+static unsigned ban_batch;
 static int ban_shutdown = 0;
 
 /*--------------------------------------------------------------------
@@ -1057,7 +1058,6 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
 	unsigned tests;
 	int i;
 
-	(void)wrk;
 	/*
 	 * First see if there is anything to do, and if so, insert marker
 	 */
@@ -1070,6 +1070,10 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
 		return;
 
 	while (1) {
+		if (++ban_batch > cache_param->ban_lurker_batch) {
+			VTIM_sleep(cache_param->ban_lurker_sleep);
+			ban_batch = 0;
+		}
 		oc = ban_lurker_getfirst(vsl, bt);
 		if (oc == NULL)
 			return;
@@ -1107,6 +1111,7 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl)
 {
 	struct ban *b, *bt;
 	struct banhead_s obans;
+	double d;
 	int i;
 
 	/* Make a list of the bans we can do something about */
@@ -1115,6 +1120,7 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl)
 	b = ban_start;
 	Lck_Unlock(&ban_mtx);
 	i = 0;
+	d = VTIM_real() - cache_param->ban_lurker_age;
 	while (b != NULL) {
 		if (b->flags & BANS_FLAG_COMPLETED) {
 			;
@@ -1122,6 +1128,8 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl)
 			;
 		} else if (b == VTAILQ_LAST(&ban_head, banhead_s)) {
 			;
+		} else if (ban_time(b->spec) > d) {
+			;
 		} else {
 			VTAILQ_INSERT_TAIL(&obans, b, l_list);
 			i++;
diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h
index 58c7e9b..7e208af 100644
--- a/bin/varnishd/common/params.h
+++ b/bin/varnishd/common/params.h
@@ -177,8 +177,9 @@ struct params {
 	/* Get rid of duplicate bans */
 	unsigned		ban_dups;
 
-	/* How long time does the ban lurker sleep */
+	double			ban_lurker_age;
 	double			ban_lurker_sleep;
+	unsigned		ban_lurker_batch;
 
 	unsigned		syslog_cli_traffic;
 
diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c
index 6c4e1e1..e63ce33 100644
--- a/bin/varnishd/mgt/mgt_param_tbl.c
+++ b/bin/varnishd/mgt/mgt_param_tbl.c
@@ -464,6 +464,16 @@ struct parspec mgt_parspec[] = {
 		"Log all CLI traffic to syslog(LOG_INFO).",
 		0,
 		"on", "bool" },
+	{ "ban_lurker_age", tweak_timeout,
+		&mgt_param.ban_lurker_age,
+		"0", NULL,
+		"The ban lurker does not process bans until they are this"
+		" old.  Right when a ban is added, the most frequently hit"
+		" objects will get tested against it as part of object"
+		" lookup.  This parameter prevents the ban-lurker from"
+		" kicking in, until the rush is over.",
+		0,
+		"60", "s" },
 	{ "ban_lurker_sleep", tweak_timeout,
 		&mgt_param.ban_lurker_sleep,
 		"0", NULL,
@@ -474,6 +484,14 @@ struct parspec mgt_parspec[] = {
 		"A value of zero disables the ban lurker.",
 		0,
 		"0.01", "s" },
+	{ "ban_lurker_batch", tweak_uint,
+		&mgt_param.ban_lurker_batch,
+		"1", NULL,
+		"How many objects the ban lurker examines before taking a"
+		" ban_lurker_sleep.  Use this to pace the ban lurker so it"
+		" does not eat too much CPU.",
+		0,
+		"1000", "" },
 	{ "http_range_support", tweak_bool, &mgt_param.http_range_support,
 		NULL, NULL,
 		"Enable support for HTTP Range headers.",
diff --git a/bin/varnishtest/tests/c00049.vtc b/bin/varnishtest/tests/c00049.vtc
index 70620da..40f7b94 100644
--- a/bin/varnishtest/tests/c00049.vtc
+++ b/bin/varnishtest/tests/c00049.vtc
@@ -37,6 +37,7 @@ server s1 {
 
 varnish v1 -vcl+backend {} -start
 
+varnish v1 -cliok "param.set ban_lurker_age 0"
 varnish v1 -cliok "param.set ban_lurker_sleep 0"
 varnish v1 -cliok "param.set debug +lurker"
 
diff --git a/bin/varnishtest/tests/r01030.vtc b/bin/varnishtest/tests/r01030.vtc
index ca7ef88..fcc9594 100644
--- a/bin/varnishtest/tests/r01030.vtc
+++ b/bin/varnishtest/tests/r01030.vtc
@@ -25,7 +25,7 @@ varnish v1 -vcl+backend {
 	}
 } -start
 
-varnish v1 -cliok "param.set ban_lurker_sleep 0.01"
+varnish v1 -cliok "param.set ban_lurker_age 0"
 varnish v1 -expect bans_tests_tested == 0
 
 delay 0.01



More information about the varnish-commit mailing list