r2389 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Jan 28 10:01:39 CET 2008


Author: phk
Date: 2008-01-28 10:01:38 +0100 (Mon, 28 Jan 2008)
New Revision: 2389

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
Log:
With Vary, Prefetch and degraded mode, a session sleeps not on a 
particular object, because we cannot know beforehand if it will work out
for us, but sleeps on any one of potentially multiple busy objects becoming
ready for us to test against.

Therefore it makes sense to move the waiting list from the object to the
object head, as this both simplifies the code and eliminates a refhold on
busy objects.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-01-28 08:46:15 UTC (rev 2388)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-01-28 09:01:38 UTC (rev 2389)
@@ -267,8 +267,6 @@
 
 	VTAILQ_HEAD(, storage)	store;
 
-	VTAILQ_HEAD(, sess)	waitinglist;
-
 	VTAILQ_HEAD(, esi_bit)	esibits;
 
 	double			lru_stamp;
@@ -283,6 +281,7 @@
 	VTAILQ_HEAD(,object)	objects;
 	char			*hash;
 	unsigned		hashlen;
+	VTAILQ_HEAD(, sess)	waitinglist;
 };
 
 /* -------------------------------------------------------------------*/
@@ -339,6 +338,7 @@
 	struct backend		*backend;
 	struct bereq		*bereq;
 	struct object		*obj;
+	struct objhead		*objhead;
 	struct VCL_conf		*vcl;
 
 	/* Various internal stuff */

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2008-01-28 08:46:15 UTC (rev 2388)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2008-01-28 09:01:38 UTC (rev 2389)
@@ -541,7 +541,7 @@
 		 * We hit a busy object, disembark worker thread and expect
 		 * hash code to restart us, still in STP_LOOKUP, later.
 		 */
-		WSP(sp, SLT_Debug, "on waiting list on obj %u", sp->obj->xid);
+		WSP(sp, SLT_Debug, "on waiting list <%s>", sp->objhead->hash);
 		/*
 		 * There is a non-zero risk that we come here more than once
 		 * before we get through, in that case cnt_recv must be set

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-01-28 08:46:15 UTC (rev 2388)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-01-28 09:01:38 UTC (rev 2389)
@@ -81,6 +81,7 @@
 		XXXAN(w->nobjhead);
 		w->nobjhead->magic = OBJHEAD_MAGIC;
 		VTAILQ_INIT(&w->nobjhead->objects);
+		VTAILQ_INIT(&w->nobjhead->waitinglist);
 		MTX_INIT(&w->nobjhead->mtx);
 		VSL_stats->n_objecthead++;
 	} else
@@ -98,7 +99,6 @@
 		w->nobj->busy = 1;
 		w->nobj->refcnt = 1;
 		VTAILQ_INIT(&w->nobj->store);
-		VTAILQ_INIT(&w->nobj->waitinglist);
 		VTAILQ_INIT(&w->nobj->esibits);
 		VSL_stats->n_object++;
 	} else
@@ -183,10 +183,10 @@
 	h = sp->http;
 
 	HSH_Prealloc(sp);
-	if (sp->obj != NULL) {
-		CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
-		oh = sp->obj->objhead;
-		HSH_Deref(sp->obj);
+	if (sp->objhead != NULL) {
+		CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
+		oh = sp->objhead;
+		sp->objhead = NULL;
 		CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 		LOCK(&oh->mtx);
 	} else {
@@ -199,9 +199,8 @@
 
 	VTAILQ_FOREACH(o, &oh->objects, list) {
 		if (o->busy) {
-			VTAILQ_INSERT_TAIL(&o->waitinglist, sp, list);
-			sp->obj = o;
-			o->refcnt++;
+			VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list);
+			sp->objhead = oh;
 			UNLOCK(&oh->mtx);
 			return (NULL);
 		}
@@ -245,16 +244,16 @@
 }
 
 static void
-hsh_rush(struct object *o)
+hsh_rush(struct objhead *oh)
 {
 	unsigned u;
 	struct sess *sp;
 
 	for (u = 0; u < params->rush_exponent; u++) {
-		sp = VTAILQ_FIRST(&o->waitinglist);
+		sp = VTAILQ_FIRST(&oh->waitinglist);
 		if (sp == NULL)
 			return;
-		VTAILQ_REMOVE(&o->waitinglist, sp, list);
+		VTAILQ_REMOVE(&oh->waitinglist, sp, list);
 		VSL(SLT_Debug, sp->id, "of waiting list");
 		WRK_QueueSession(sp);
 	}
@@ -276,7 +275,7 @@
 		LOCK(&oh->mtx);
 	}
 	o->busy = 0;
-	hsh_rush(o);
+	hsh_rush(oh);
 	if (oh != NULL)
 		UNLOCK(&oh->mtx);
 }
@@ -314,7 +313,7 @@
 	}
 	assert(o->refcnt > 0);
 	r = --o->refcnt;
-	hsh_rush(o);
+	hsh_rush(oh);
 	if (oh != NULL) {
 		if (!r)
 			VTAILQ_REMOVE(&oh->objects, o, list);




More information about the varnish-commit mailing list