r2294 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Dec 11 13:04:59 CET 2007


Author: phk
Date: 2007-12-11 13:04:58 +0100 (Tue, 11 Dec 2007)
New Revision: 2294

Modified:
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/mgt_param.c
Log:
When an object is being fetched from the backend, other requests for it
are parked not holding a worker thread, until the fetching session lowers
the busy bit on the object.

At that point we would release all the parked requests into the thread
pool to be serviced, causing instant congestion and calls for road-pricing
if the backend were a bit slow on an oft-requested object.

Change the restart policy to be paced exponential:

When we clear the busy bits, we unpark "rush_exponent" requests into
the thread pool to start the show.

Whenever the object is dereferenced, in practice whenever a request
has been serviced, another "rush_exponent" worth of requests are
unparked into the tread pool.

Set the parameter to a conservative 3 until we know more about the
behaviour in practice.

If it is a big object and/or the clients are on slow lines, 3 may
be an order of magnitude to small.

Attempts to fix: #188



Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2007-12-11 09:03:51 UTC (rev 2293)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2007-12-11 12:04:58 UTC (rev 2294)
@@ -244,11 +244,26 @@
 	return (o);
 }
 
+static void
+hsh_rush(struct object *o)
+{
+	unsigned u;
+	struct sess *sp;
+
+	for (u = 0; u < params->rush_exponent; u++) {
+		sp = VTAILQ_FIRST(&o->waitinglist);
+		if (sp == NULL)
+			return;
+		VTAILQ_REMOVE(&o->waitinglist, sp, list);
+		VSL(SLT_Debug, sp->id, "of waiting list");
+		WRK_QueueSession(sp);
+	}
+}
+
 void
 HSH_Unbusy(struct object *o)
 {
 	struct objhead *oh;
-	struct sess *sp;
 
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	assert(o->busy);
@@ -261,15 +276,9 @@
 		LOCK(&oh->mtx);
 	}
 	o->busy = 0;
+	hsh_rush(o);
 	if (oh != NULL)
 		UNLOCK(&oh->mtx);
-	while (1) {
-		sp = VTAILQ_FIRST(&o->waitinglist);
-		if (sp == NULL)
-			break;
-		VTAILQ_REMOVE(&o->waitinglist, sp, list);
-		WRK_QueueSession(sp);
-	}
 }
 
 void
@@ -305,6 +314,7 @@
 	}
 	assert(o->refcnt > 0);
 	r = --o->refcnt;
+	hsh_rush(o);
 	if (oh != NULL) {
 		if (!r)
 			VTAILQ_REMOVE(&oh->objects, o, list);

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2007-12-11 09:03:51 UTC (rev 2293)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2007-12-11 12:04:58 UTC (rev 2294)
@@ -131,6 +131,8 @@
 	/* Maximum esi:include depth allowed */
 	unsigned		max_esi_includes;
 
+	/* Rush exponent */
+	unsigned		rush_exponent;
 };
 
 extern volatile struct params *params;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2007-12-11 09:03:51 UTC (rev 2293)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2007-12-11 12:04:58 UTC (rev 2294)
@@ -295,6 +295,17 @@
 /*--------------------------------------------------------------------*/
 
 static void
+tweak_rush_exponent(struct cli *cli, struct parspec *par, const char *arg)
+{
+
+	(void)par;
+	tweak_generic_uint(cli, &master.rush_exponent, arg,
+	    2, UINT_MAX);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
 tweak_http_workspace(struct cli *cli, struct parspec *par, const char *arg)
 {
 
@@ -642,6 +653,14 @@
 		"thread_pool_max parameter.",
 		EXPERIMENTAL,
 		"100", "%" },
+	{ "rush_exponent", tweak_rush_exponent,
+		"How many parked request we start for each completed "
+		"request on the object.\n"
+		"NB: Even with the implict delay of delivery, "
+		"this parameter controls an exponential increase in "
+		"number of worker threads.  ",
+		EXPERIMENTAL,
+		"3", "requests per request" },
 	{ "http_workspace", tweak_http_workspace,
 		"Bytes of HTTP protocol workspace allocated. "
 		"This space must be big enough for the entire HTTP protocol "




More information about the varnish-commit mailing list