r2390 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Jan 28 10:09:12 CET 2008


Author: phk
Date: 2008-01-28 10:09:12 +0100 (Mon, 28 Jan 2008)
New Revision: 2390

Modified:
   trunk/varnish-cache/bin/varnishd/cache_hash.c
Log:
Instead of sleeping as soon as we see a busy object, traverse the rest
of the objects on the objecthead to see if there is anything we can use.

This unpessimizes Vary: processing, where we previously might go to sleep
on a busy object despite the fact that we have a good and valid object
with the Vary: we desire.



Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-01-28 09:01:38 UTC (rev 2389)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-01-28 09:09:12 UTC (rev 2390)
@@ -173,7 +173,7 @@
 	struct worker *w;
 	struct http *h;
 	struct objhead *oh;
-	struct object *o;
+	struct object *o, *busy_o;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
@@ -197,12 +197,11 @@
 		LOCK(&oh->mtx);
 	}
 
+	busy_o = NULL;
 	VTAILQ_FOREACH(o, &oh->objects, list) {
 		if (o->busy) {
-			VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list);
-			sp->objhead = oh;
-			UNLOCK(&oh->mtx);
-			return (NULL);
+			busy_o = o;
+			continue;
 		}
 		if (!o->cacheable)
 			continue;
@@ -221,12 +220,21 @@
 			break;
 	}
 	if (o != NULL) {
+		/* We found an object we like */
 		o->refcnt++;
 		UNLOCK(&oh->mtx);
 		(void)hash->deref(oh);
 		return (o);
 	}
 
+	if (busy_o != NULL) {
+		/* There are one or more busy objects, wait for them */
+		VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list);
+		sp->objhead = oh;
+		UNLOCK(&oh->mtx);
+		return (NULL);
+	}
+
 	/* Insert (precreated) object in objecthead */
 	o = w->nobj;
 	w->nobj = NULL;




More information about the varnish-commit mailing list