r3878 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Wed Mar 4 13:13:54 CET 2009


Author: phk
Date: 2009-03-04 13:13:54 +0100 (Wed, 04 Mar 2009)
New Revision: 3878

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_cli.c
   trunk/varnish-cache/bin/varnishd/cache_esi.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/bin/varnishd/rfc2616.c
   trunk/varnish-cache/include/stat_field.h
Log:
Integrate the rest of bereq into the worker structure.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-03-04 12:13:54 UTC (rev 3878)
@@ -225,6 +225,13 @@
 	struct http		*beresp1;
 	struct http		*beresp;
 	struct http		*resp;
+
+	unsigned		cacheable;
+	double			age;
+	double			entered;
+	double			ttl;
+	double			grace;
+	unsigned		do_esi;
 };
 
 /* Work Request for worker thread ------------------------------------*/
@@ -242,20 +249,6 @@
 	void			*priv;
 };
 
-/* Backend Request ---------------------------------------------------*/
-
-struct bereq {
-	unsigned		magic;
-#define BEREQ_MAGIC		0x3b6d250c
-	VTAILQ_ENTRY(bereq)	list;
-	unsigned		cacheable;
-	double			age;
-	double			entered;
-	double			ttl;
-	double			grace;
-	unsigned		do_esi;
-};
-
 /* Storage -----------------------------------------------------------*/
 
 struct storage {
@@ -398,7 +391,6 @@
 
 	struct director		*director;
 	struct vbe_conn		*vbe;
-	struct bereq		*bereq;
 	struct object		*obj;
 	struct objcore		*objcore;
 	struct objhead		*objhead;
@@ -443,8 +435,6 @@
 void VBE_GetFd(struct sess *sp);
 void VBE_ClosedFd(struct sess *sp);
 void VBE_RecycleFd(struct sess *sp);
-struct bereq * VBE_new_bereq(struct sess *sp);
-void VBE_free_bereq(struct bereq **bereq);
 void VBE_AddHostHeader(const struct sess *sp);
 void VBE_Poll(void);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -51,11 +51,6 @@
  */
 static VTAILQ_HEAD(,vbe_conn) vbe_conns = VTAILQ_HEAD_INITIALIZER(vbe_conns);
 
-/*
- * List of cached bereq's
- */
-static VTAILQ_HEAD(,bereq) bereq_head = VTAILQ_HEAD_INITIALIZER(bereq_head);
-
 /*--------------------------------------------------------------------
  * Create default Host: header for backend request
  */
@@ -64,7 +59,6 @@
 {
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk->bereq, HTTP_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vbe, VBE_CONN_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vbe->backend, BACKEND_MAGIC);
@@ -135,54 +129,6 @@
 }
 
 /*--------------------------------------------------------------------
- * Get a bereq structure for talking HTTP with the backend.
- * First attempt to pick one from our stash, else make a new.
- *
- * Can fail with NULL.
- */
-
-struct bereq *
-VBE_new_bereq(struct sess *sp)
-{
-	struct bereq *bereq;
-
-	Lck_Lock(&VBE_mtx);
-	bereq = VTAILQ_FIRST(&bereq_head);
-	if (bereq != NULL)
-		VTAILQ_REMOVE(&bereq_head, bereq, list);
-	Lck_Unlock(&VBE_mtx);
-	if (bereq != NULL) {
-		CHECK_OBJ(bereq, BEREQ_MAGIC);
-	} else {
-		bereq = calloc(sizeof *bereq, 1);
-		if (bereq == NULL)
-			return (NULL);
-		bereq->magic = BEREQ_MAGIC;
-		sp->wrk->stats->n_bereq++;
-	}
-	return (bereq);
-}
-
-/*--------------------------------------------------------------------
- * Return a bereq to the stash.
- */
-
-void
-VBE_free_bereq(struct bereq **bereqp)
-{
-	struct bereq *bereq;
-
-	AN(bereqp);
-	bereq = *bereqp;
-	*bereqp = NULL;
-
-	CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC);
-	Lck_Lock(&VBE_mtx);
-	VTAILQ_INSERT_HEAD(&bereq_head, bereq, list);
-	Lck_Unlock(&VBE_mtx);
-}
-
-/*--------------------------------------------------------------------
  * Manage a pool of vbe_conn structures.
  * XXX: as an experiment, make this caching controled by a parameter
  * XXX: so we can see if it has any effect.

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -155,8 +155,6 @@
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
 
-	AZ(sp->bereq);
-
 	sp->t_resp = TIM_real();
 	if (sp->obj->objhead != NULL) {
 		if ((sp->t_resp - sp->obj->last_lru) > params->lru_timeout &&
@@ -208,7 +206,6 @@
 
 	AZ(sp->obj);
 	AZ(sp->vbe);
-	AZ(sp->bereq);
 	sp->director = NULL;
 	sp->restarts = 0;
 
@@ -305,7 +302,6 @@
 	char date[40];
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	AZ(sp->bereq);
 
 	/* We always close when we take this path */
 	sp->doclose = "error";
@@ -386,7 +382,6 @@
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
 
-	AN(sp->bereq);
 	AN(sp->director);
 	AZ(sp->vbe);
 
@@ -404,7 +399,6 @@
 	if (i) {
 		sp->err_code = 503;
 		sp->step = STP_ERROR;
-		VBE_free_bereq(&sp->bereq);
 		if (sp->objhead) {
 			CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
 			CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
@@ -428,22 +422,22 @@
 	case 302: /* Moved Temporarily */
 	case 410: /* Gone */
 	case 404: /* Not Found */
-		sp->bereq->cacheable = 1;
+		sp->wrk->cacheable = 1;
 		break;
 	default:
-		sp->bereq->cacheable = 0;
+		sp->wrk->cacheable = 0;
 		break;
 	}
 
-	sp->bereq->entered = TIM_real();
-	sp->bereq->age = 0;
-	sp->bereq->ttl = RFC2616_Ttl(sp);
+	sp->wrk->entered = TIM_real();
+	sp->wrk->age = 0;
+	sp->wrk->ttl = RFC2616_Ttl(sp);
 
-	if (sp->bereq->ttl == 0.)
-		sp->bereq->cacheable = 0;
+	if (sp->wrk->ttl == 0.)
+		sp->wrk->cacheable = 0;
 
-	sp->bereq->do_esi = 0;
-	sp->bereq->grace = NAN;
+	sp->wrk->do_esi = 0;
+	sp->wrk->grace = NAN;
 
 	VCL_fetch_method(sp);
 
@@ -470,13 +464,13 @@
 
 	sp->obj->xid = sp->xid;
 	sp->obj->response = sp->err_code;
-	sp->obj->cacheable = sp->bereq->cacheable;
-	sp->obj->ttl = sp->bereq->ttl;
-	sp->obj->grace = sp->bereq->grace;
+	sp->obj->cacheable = sp->wrk->cacheable;
+	sp->obj->ttl = sp->wrk->ttl;
+	sp->obj->grace = sp->wrk->grace;
 	if (sp->obj->ttl == 0.)
 		sp->obj->cacheable = 0;
-	sp->obj->age = sp->bereq->age;
-	sp->obj->entered = sp->bereq->entered;
+	sp->obj->age = sp->wrk->age;
+	sp->obj->entered = sp->wrk->entered;
 	WS_Assert(sp->obj->ws_o);
 
 	/* Filter into object */
@@ -499,17 +493,14 @@
 	if (i) {
 		sp->err_code = 503;
 		sp->step = STP_ERROR;
-		VBE_free_bereq(&sp->bereq);
 		HSH_Drop(sp);
 		AZ(sp->obj);
 		return (0);
 	}
 
-	if (sp->bereq->do_esi)
+	if (sp->wrk->do_esi)
 		ESI_Parse(sp);
 
-	VBE_free_bereq(&sp->bereq);
-
 	switch (handling) {
 	case VCL_RET_RESTART:
 		HSH_Drop(sp);
@@ -783,11 +774,9 @@
 	switch(sp->handling) {
 	case VCL_RET_ERROR:
 		HSH_DerefObjCore(sp);
-		VBE_free_bereq(&sp->bereq);
 		sp->step = STP_ERROR;
 		return (0);
 	case VCL_RET_PASS:
-		VBE_free_bereq(&sp->bereq);
 		HSH_DerefObjCore(sp);
 		sp->step = STP_PASS;
 		return (0);
@@ -796,7 +785,6 @@
 		return (0);
 	case VCL_RET_RESTART:
 		HSH_DerefObjCore(sp);
-		VBE_free_bereq(&sp->bereq);
 		INCOMPL();
 	default:
 		WRONG("Illegal action in vcl_miss{}");
@@ -848,7 +836,6 @@
 
 	VCL_pass_method(sp);
 	if (sp->handling == VCL_RET_ERROR) {
-		VBE_free_bereq(&sp->bereq);
 		sp->step = STP_ERROR;
 		return (0);
 	}
@@ -902,7 +889,6 @@
 	assert(sp->handling == VCL_RET_PIPE);
 
 	PipeSession(sp);
-	AZ(sp->bereq);
 	AZ(sp->wrk->wfd);
 	sp->step = STP_DONE;
 	return (0);

Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -189,7 +189,6 @@
 	SZOF(struct acct);
 	SZOF(struct worker);
 	SZOF(struct workreq);
-	SZOF(struct bereq);
 	SZOF(struct storage);
 	SZOF(struct object);
 	SZOF(struct objcore);

Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -397,7 +397,6 @@
 			 * different and have been rewritten underway.
 			 */
 			CHECK_OBJ_NOTNULL(ew->sp, SESS_MAGIC);
-			CHECK_OBJ_NOTNULL(ew->sp->bereq, BEREQ_MAGIC);
 			CHECK_OBJ_NOTNULL(ew->sp->wrk->bereq, HTTP_MAGIC);
 			tag = ew->sp->wrk->bereq->hd[HTTP_HDR_URL];
 

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -314,12 +314,10 @@
 	struct worker *w;
 	char *b;
 	struct http *hp;
-	struct bereq *bereq;
 	int i;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
 	AN(sp->director);
 	AZ(sp->obj);
 	if (sp->objcore != NULL) {		/* pass has no objcore */
@@ -327,12 +325,10 @@
 		AN(sp->objhead);		/* details in hash_slinger.h */
 		AN(sp->objcore->flags & OC_F_BUSY);
 	}
-	AN(sp->bereq);
 
 	/* Transmit request */
 
 	w = sp->wrk;
-	bereq = sp->bereq;
 	hp = sp->wrk->bereq;
 
 	VBE_GetFd(sp);
@@ -410,14 +406,12 @@
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->obj->http, HTTP_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
 
 	/* We use the unmodified headers */
 	hp = sp->wrk->beresp1;
 	AN(sp->director);
 	if (sp->obj->objcore != NULL)		/* pass has no objcore */
 		AN(ObjIsBusy(sp->obj));
-	AN(sp->bereq);
 
 	vc = sp->vbe;
 

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -631,13 +631,10 @@
 void
 http_FilterHeader(struct sess *sp, unsigned how)
 {
-	struct bereq *bereq;
 	struct http *hp;
 
-	AZ(sp->bereq);
-	bereq = VBE_new_bereq(sp);
-	AN(bereq);
 	hp = sp->wrk->bereq;
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	hp->logtag = HTTP_Tx;
 
 	http_copyreq(hp, sp->http, how);
@@ -645,8 +642,6 @@
 	http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
 	http_PrintfHeader(sp->wrk, sp->fd, hp,
 	    "X-Forwarded-For: %s", sp->addr);
-
-	sp->bereq = bereq;
 }
 
 /*--------------------------------------------------------------------

Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -67,15 +67,12 @@
 {
 	struct vbe_conn *vc;
 	struct worker *w;
-	struct bereq *bereq;
 	struct pollfd fds[2];
 	int i;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
 	w = sp->wrk;
-	bereq = sp->bereq;
-	sp->bereq = NULL;
 
 	VBE_GetFd(sp);
 	if (sp->vbe == NULL)
@@ -91,7 +88,6 @@
 		    WRW_Write(w, sp->htc->pipeline.b, Tlen(sp->htc->pipeline));
 
 	i = WRW_FlushRelease(w);
-	VBE_free_bereq(&bereq);
 
 	if (i) {
 		vca_close_session(sp, "pipe");

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -313,16 +313,14 @@
 VRT_l_##dir##_##onm(const struct sess *sp, type a)			\
 {									\
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);				\
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);	/* XXX */	\
-	sp->bereq->field = a;						\
+	sp->wrk->field = a;						\
 }									\
 									\
 type									\
 VRT_r_##dir##_##onm(const struct sess *sp)				\
 {									\
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);				\
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);	/* XXX */	\
-	return (sp->bereq->field);					\
+	return (sp->wrk->field);					\
 }
 
 VBEREQ(beresp, unsigned, cacheable, cacheable)
@@ -344,7 +342,6 @@
 {
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);	/* XXX */
 	WSP(sp, SLT_TTL, "%u VCL %.0f %.0f", sp->xid, a, sp->t_req);
 	/*
 	 * If people set obj.ttl = 0s, they don't expect it to be cacheable
@@ -353,17 +350,16 @@
 	 * We special case and make sure that rounding does not surprise.
 	 */
 	if (a <= 0)
-		sp->bereq->ttl = sp->t_req - 1;
+		sp->wrk->ttl = sp->t_req - 1;
 	else
-		sp->bereq->ttl = sp->t_req + a;
+		sp->wrk->ttl = sp->t_req + a;
 }
 
 double
 VRT_r_beresp_ttl(const struct sess *sp)
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);	/* XXX */
-	return (sp->bereq->ttl - sp->t_req);
+	return (sp->wrk->ttl - sp->t_req);
 }
 
 void
@@ -384,7 +380,6 @@
 VRT_r_beresp_status(const struct sess *sp)
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
 	/* XXX: use http_GetStatus() */
 	if (sp->wrk->beresp->status)
 		return (sp->wrk->beresp->status);
@@ -780,7 +775,6 @@
 void
 VRT_ESI(struct sess *sp)
 {
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
 
 	if (sp->cur_method != VCL_MET_FETCH) {
 		/* XXX: we should catch this at compile time */
@@ -789,7 +783,7 @@
 		return;
 	}
 
-	sp->bereq->do_esi = 1;
+	sp->wrk->do_esi = 1;
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/rfc2616.c	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/bin/varnishd/rfc2616.c	2009-03-04 12:13:54 UTC (rev 3878)
@@ -77,10 +77,9 @@
 	char *p;
 	const struct http *hp;
 
-	CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
 	hp = sp->wrk->beresp;
 
-	assert(sp->bereq->entered != 0.0 && !isnan(sp->bereq->entered));
+	assert(sp->wrk->entered != 0.0 && !isnan(sp->wrk->entered));
 	/* If all else fails, cache using default ttl */
 	ttl = params->default_ttl;
 
@@ -103,7 +102,7 @@
 			max_age = strtoul(p, NULL, 0);
 			if (http_GetHdr(hp, H_Age, &p)) {
 				age = strtoul(p, NULL, 0);
-				sp->bereq->age = age;
+				sp->wrk->age = age;
 			}
 
 			if (age > max_age)
@@ -130,14 +129,14 @@
 		}
 
 		if (h_date == 0 ||
-		    (h_date < sp->bereq->entered + params->clock_skew &&
-		    h_date + params->clock_skew > sp->bereq->entered)) {
+		    (h_date < sp->wrk->entered + params->clock_skew &&
+		    h_date + params->clock_skew > sp->wrk->entered)) {
 			/*
 			 * If we have no Date: header or if it is
 			 * sufficiently close to our clock we will
 			 * trust Expires: relative to our own clock.
 			 */
-			if (h_expires < sp->bereq->entered)
+			if (h_expires < sp->wrk->entered)
 				ttl = 0;
 			else
 				ttd = h_expires;
@@ -154,12 +153,12 @@
 	} while (0);
 
 	if (ttl > 0 && ttd == 0)
-		ttd = sp->bereq->entered + ttl;
+		ttd = sp->wrk->entered + ttl;
 
 	/* calculated TTL, Our time, Date, Expires, max-age, age */
 	WSP(sp, SLT_TTL, "%u RFC %d %d %d %d %u %u", sp->xid,
-	    ttd ? (int)(ttd - sp->bereq->entered) : 0,
-	    (int)sp->bereq->entered, (int)h_date,
+	    ttd ? (int)(ttd - sp->wrk->entered) : 0,
+	    (int)sp->wrk->entered, (int)h_date,
 	    (int)h_expires, max_age, age);
 
 	return (ttd);

Modified: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h	2009-03-04 11:45:10 UTC (rev 3877)
+++ trunk/varnish-cache/include/stat_field.h	2009-03-04 12:13:54 UTC (rev 3878)
@@ -55,7 +55,6 @@
 MAC_STAT(n_smf_frag,		uint64_t, 0, 'i', "N small free smf")
 MAC_STAT(n_smf_large,		uint64_t, 0, 'i', "N large free smf")
 MAC_STAT(n_vbe_conn,		uint64_t, 0, 'i', "N struct vbe_conn")
-MAC_STAT(n_bereq,		uint64_t, 1, 'i', "N struct bereq")
 MAC_STAT(n_wrk,			uint64_t, 0, 'i', "N worker threads")
 MAC_STAT(n_wrk_create,		uint64_t, 0, 'a', "N worker threads created")
 MAC_STAT(n_wrk_failed,		uint64_t, 0, 'a', "N worker threads not created")



More information about the varnish-commit mailing list