]> err.no Git - varnish/commitdiff
Instead of sleeping as soon as we see a busy object, traverse the rest
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 28 Jan 2008 09:09:12 +0000 (09:09 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 28 Jan 2008 09:09:12 +0000 (09:09 +0000)
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.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2390 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_hash.c

index df3fc0078f7630a592be6a6c41729f698d2b5c96..eafa0852a03e79181fc4679b423460d97c2ce211 100644 (file)
@@ -173,7 +173,7 @@ HSH_Lookup(struct sess *sp)
        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 @@ HSH_Lookup(struct sess *sp)
                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 @@ HSH_Lookup(struct sess *sp)
                        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;