From 426553907c07a0f741d66f524395c149f7d9ef6e Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 28 Jan 2008 09:09:12 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2390 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_hash.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index df3fc007..eafa0852 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -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; -- 2.39.5