r3842 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Sat Feb 28 19:34:08 CET 2009


Author: phk
Date: 2009-02-28 19:34:07 +0100 (Sat, 28 Feb 2009)
New Revision: 3842

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/hash_slinger.h
Log:
Now that we do not need the new object while holding the highly trafficed
objhead lock, don't preallocate objects.

One unfortunate effect of this preallocation, only recently identified:

On systems with high number of worker threads and high hitrates, considerable
time could elapse between the preallocation of an object to a worker
thread and the use of that object.

This could make cache-misses use a much larger working set size than
really necessary.

I do not have access to any benchmarks that show a credible performance
difference, but reports are most welcome.




Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-02-28 18:18:23 UTC (rev 3841)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-02-28 18:34:07 UTC (rev 3842)
@@ -194,7 +194,6 @@
 	unsigned		magic;
 #define WORKER_MAGIC		0x6391adcf
 	struct objhead		*nobjhead;
-	struct object		*nobj;
 	struct objcore		*nobjcore;
 	struct dstat		*stats;
 

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-02-28 18:18:23 UTC (rev 3841)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-02-28 18:34:07 UTC (rev 3842)
@@ -314,10 +314,9 @@
 	w = sp->wrk;
 	if (sp->obj == NULL) {
 		HSH_Prealloc(sp);
-		sp->obj = sp->wrk->nobj;
+		sp->obj = HSH_NewObject(sp);
 		sp->obj->xid = sp->xid;
 		sp->obj->entered = sp->t_req;
-		sp->wrk->nobj = NULL;
 	} else {
 		/* XXX: Null the headers ? */
 	}
@@ -683,8 +682,7 @@
 		VSL_stats->cache_miss++;
 
 		AZ(oc->obj);
-		o = sp->wrk->nobj;
-		sp->wrk->nobj = NULL;
+		o = HSH_NewObject(sp);
 
 		o->objhead = oh;
 		o->objcore = oc;
@@ -821,8 +819,7 @@
 	assert(sp->handling == VCL_RET_PASS);
 	sp->acct_req.pass++;
 	HSH_Prealloc(sp);
-	sp->obj = sp->wrk->nobj;
-	sp->wrk->nobj = NULL;
+	sp->obj = HSH_NewObject(sp);
 	sp->sendbody = 1;
 	sp->step = STP_FETCH;
 	return (0);
@@ -1078,7 +1075,6 @@
 		CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 		CHECK_OBJ_ORNULL(sp->obj, OBJECT_MAGIC);
 		CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
-		CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
 		CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
 
 		switch (sp->step) {
@@ -1093,7 +1089,6 @@
 		default:
 			WRONG("State engine misfire");
 		}
-		CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
 		CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
 	}
 	WSL_Flush(w, 0);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-02-28 18:18:23 UTC (rev 3841)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-02-28 18:34:07 UTC (rev 3842)
@@ -79,15 +79,42 @@
 	return (g);
 }
 
+struct object *
+HSH_NewObject(struct sess *sp)
+{
+	struct object *o;
+	struct storage *st;
+
+	st = STV_alloc(sp, params->obj_workspace);
+	XXXAN(st);
+	assert(st->space > sizeof *o);
+	o = (void *)st->ptr; /* XXX: align ? */
+	st->len = sizeof *o;
+	memset(o, 0, sizeof *o);
+	o->objstore = st;
+	WS_Init(o->ws_o, "obj",
+	    st->ptr + st->len, st->space - st->len);
+	st->len = st->space;
+	WS_Assert(o->ws_o);
+	http_Setup(o->http, o->ws_o);
+	o->magic = OBJECT_MAGIC;
+	o->http->magic = HTTP_MAGIC;
+	o->refcnt = 1;
+	o->grace = NAN;
+	o->entered = NAN;
+	VTAILQ_INIT(&o->store);
+	VTAILQ_INIT(&o->esibits);
+	sp->wrk->stats->n_object++;
+	return (o);
+}
+
 /* Precreate an objhead and object for later use */
 void
-HSH_Prealloc(struct sess *sp)
+HSH_Prealloc(const struct sess *sp)
 {
 	struct worker *w;
 	struct objhead *oh;
 	struct objcore *oc;
-	struct object *o;
-	struct storage *st;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
@@ -113,31 +140,6 @@
 	}
 	CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC);
 
-	if (w->nobj == NULL) {
-		st = STV_alloc(sp, params->obj_workspace);
-		XXXAN(st);
-		assert(st->space > sizeof *w->nobj);
-		o = (void *)st->ptr; /* XXX: align ? */
-		st->len = sizeof *o;
-		memset(o, 0, sizeof *o);
-		o->objstore = st;
-		WS_Init(o->ws_o, "obj",
-		    st->ptr + st->len, st->space - st->len);
-		st->len = st->space;
-		WS_Assert(o->ws_o);
-		http_Setup(o->http, o->ws_o);
-		o->magic = OBJECT_MAGIC;
-		o->http->magic = HTTP_MAGIC;
-		o->refcnt = 1;
-		o->grace = NAN;
-		o->entered = NAN;
-		VTAILQ_INIT(&o->store);
-		VTAILQ_INIT(&o->esibits);
-		w->nobj = o;
-		w->stats->n_object++;
-
-	}
-	CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC);
 }
 
 void
@@ -154,11 +156,6 @@
 		w->nobjhead = NULL;
 		w->stats->n_objecthead--;
 	}
-	if (w->nobj != NULL) {
-		STV_free(w->nobj->objstore);
-		w->nobj = NULL;
-		w->stats->n_object--;
-	}
 }
 
 void

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2009-02-28 18:18:23 UTC (rev 3841)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2009-02-28 18:34:07 UTC (rev 3842)
@@ -431,10 +431,8 @@
 	AZ(sess->wrk);
 	THR_SetSession(sess);
 	sess->wrk = w;
-	CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
 	CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
 	CNT_Session(sess);
-	CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
 	CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
 	THR_SetSession(NULL);
 }

Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-02-28 18:18:23 UTC (rev 3841)
+++ trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-02-28 18:34:07 UTC (rev 3842)
@@ -50,7 +50,8 @@
 };
 
 /* cache_hash.c */
-void HSH_Prealloc(struct sess *sp);
+struct object *HSH_NewObject(struct sess *sp);
+void HSH_Prealloc(const struct sess *sp);
 void HSH_Cleanup(struct worker *w);
 void HSH_Freestore(struct object *o);
 void HSH_Copy(const struct sess *sp, struct objhead *o);



More information about the varnish-commit mailing list