r3182 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Sep 12 10:51:02 CEST 2008


Author: phk
Date: 2008-09-12 10:51:02 +0200 (Fri, 12 Sep 2008)
New Revision: 3182

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Fix #315:

Rename worker->used to worker->lastused and make it an optimization to
set it from a convenient timestamp along the way.

If it is not set when the thread goes on the unemployment queue, expend
a timestamp on setting it.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-09-12 07:36:21 UTC (rev 3181)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-09-12 08:51:02 UTC (rev 3182)
@@ -175,7 +175,7 @@
 	struct objhead		*nobjhead;
 	struct object		*nobj;
 
-	double			used;
+	double			lastused;
 
 	pthread_cond_t		cond;
 

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2008-09-12 07:36:21 UTC (rev 3181)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2008-09-12 08:51:02 UTC (rev 3182)
@@ -218,8 +218,7 @@
 	}
 
 	sp->t_end = TIM_real();
-	sp->wrk->used = sp->t_end;
-	assert(!isnan(sp->wrk->used));
+	sp->wrk->lastused = sp->t_end;
 	if (sp->xid == 0) {
 		sp->t_req = sp->t_end;
 		sp->t_resp = sp->t_end;
@@ -236,10 +235,8 @@
 	WSL_Flush(sp->wrk, 0);
 
 	/* If we did an ESI include, don't mess up our state */
-	if (sp->esis > 0) {
-		assert(!isnan(sp->wrk->used));
+	if (sp->esis > 0)
 		return (1);
-	}
 
 	sp->t_req = NAN;
 
@@ -248,7 +245,6 @@
 	if (sp->fd < 0) {
 		SES_Charge(sp);
 		VSL_stats->sess_closed++;
-		assert(!isnan(sp->wrk->used));
 		sp->wrk = NULL;
 		SES_Delete(sp);
 		return (1);
@@ -281,7 +277,6 @@
 	}
 	VSL_stats->sess_herd++;
 	SES_Charge(sp);
-	assert(!isnan(sp->wrk->used));
 	sp->wrk = NULL;
 	vca_return_session(sp);
 	return (1);
@@ -465,8 +460,7 @@
 
 	/* Receive a HTTP protocol request */
 	HTC_Init(sp->htc, sp->ws, sp->fd);
-	sp->wrk->used = sp->t_open;
-	assert(!isnan(sp->wrk->used));
+	sp->wrk->lastused = sp->t_open;
 	sp->wrk->acct.sess++;
 	SES_RefSrcAddr(sp);
 	do
@@ -618,13 +612,6 @@
 		if (params->diag_bitmap & 0x20)
 			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
-		 */
-		if (isnan(sp->wrk->used))
-			sp->wrk->used = TIM_real();
-		assert(!isnan(sp->wrk->used));
 		SES_Charge(sp);
 		return (1);
 	}
@@ -869,7 +856,6 @@
 			/* XXX: VSL something */
 			INCOMPL();
 			sp->step = STP_DONE;
-			assert(!isnan(sp->wrk->used));
 			return (1);
 		}
 		sp->step = STP_PIPE;
@@ -908,8 +894,7 @@
 	/* Update stats of various sorts */
 	VSL_stats->client_req++;			/* XXX not locked */
 	sp->t_req = TIM_real();
-	sp->wrk->used = sp->t_req;
-	assert(!isnan(sp->wrk->used));
+	sp->wrk->lastused = sp->t_req;
 	sp->wrk->acct.req++;
 
 	/* Assign XID and log */
@@ -977,6 +962,15 @@
 	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
 
 	/*
+	 * Possible entrance states
+	 */
+	assert(
+	    sp->step == STP_FIRST ||
+	    sp->step == STP_START ||
+	    sp->step == STP_LOOKUP ||
+	    sp->step == STP_RECV);
+	  
+	/*
 	 * Whenever we come in from the acceptor we need to set blocking
 	 * mode, but there is no point in setting it when we come from
 	 * ESI or when a parked sessions returns.
@@ -1013,7 +1007,6 @@
 		CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
 		CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
 	}
-	assert(!isnan(w->used));
 	WSL_Flush(w, 0);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2008-09-12 07:36:21 UTC (rev 3181)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2008-09-12 08:51:02 UTC (rev 3182)
@@ -245,7 +245,7 @@
 	CAST_OBJ_NOTNULL(qp, priv, WQ_MAGIC);
 	memset(w, 0, sizeof *w);
 	w->magic = WORKER_MAGIC;
-	w->used = TIM_real();
+	w->lastused = NAN;
 	w->wlb = w->wlp = wlog;
 	w->wle = wlog + sizeof wlog;
 	AZ(pthread_cond_init(&w->cond, NULL));
@@ -256,7 +256,6 @@
 	qp->nthr++;
 	while (1) {
 		CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-		assert(!isnan(w->used));
 
 		/* Process overflow requests, if any */
 		w->wrq = VTAILQ_FIRST(&qp->overflow);
@@ -264,6 +263,8 @@
 			VTAILQ_REMOVE(&qp->overflow, w->wrq, list);
 			qp->nqueue--;
 		} else {
+			if (isnan(w->lastused))
+				w->lastused = TIM_real();
 			VTAILQ_INSERT_HEAD(&qp->idle, w, list);
 			AZ(pthread_cond_wait(&w->cond, &qp->mtx));
 		}
@@ -273,6 +274,7 @@
 		AN(w->wrq);
 		wrq = w->wrq;
 		AN(wrq->func);
+		w->lastused = NAN;
 		wrq->func(w, wrq->priv);
 		w->wrq = NULL;
 		LOCK(&qp->mtx);
@@ -359,9 +361,7 @@
 	sess->wrk = w;
 	CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
 	CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
-	w->used = NAN;
 	CNT_Session(sess);
-	assert(!isnan(w->used));
 	CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC);
 	CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC);
 	THR_SetSession(NULL);
@@ -438,7 +438,7 @@
 
 	LOCK(&qp->mtx);
 	w = VTAILQ_LAST(&qp->idle, workerhead);
-	if (w != NULL && (w->used < t_idle || qp->nthr > nthr_max))
+	if (w != NULL && (w->lastused < t_idle || qp->nthr > nthr_max))
 		VTAILQ_REMOVE(&qp->idle, w, list);
 	else
 		w = NULL;




More information about the varnish-commit mailing list