r4989 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Mon Jun 28 16:28:37 CEST 2010


Author: phk
Date: 2010-06-28 16:28:36 +0200 (Mon, 28 Jun 2010)
New Revision: 4989

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_esi.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishd/cache_session.c
Log:
Fix a problem with accounting of ESI transactions, in particular make
the Length header match the actual composite object sent to the client.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2010-06-28 11:53:33 UTC (rev 4988)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2010-06-28 14:28:36 UTC (rev 4989)
@@ -434,8 +434,9 @@
 	struct sessmem		*mem;
 
 	struct workreq		workreq;
-	struct acct		acct;
+	struct acct		acct_tmp;
 	struct acct		acct_req;
+	struct acct		acct_ses;
 
 #if defined(HAVE_EPOLL_CTL)
 	struct epoll_event ev;

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2010-06-28 11:53:33 UTC (rev 4988)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2010-06-28 14:28:36 UTC (rev 4989)
@@ -176,7 +176,7 @@
 		VSL(SLT_SessionOpen, sp->fd, "%s %s %s",
 		    sp->addr, sp->port, sp->mylsock->name);
 	}
-	sp->acct.first = sp->t_open;
+	sp->acct_ses.first = sp->t_open;
 	if (need_test)
 		sock_test(sp->fd);
 	if (need_linger)

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2010-06-28 11:53:33 UTC (rev 4988)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2010-06-28 14:28:36 UTC (rev 4989)
@@ -240,31 +240,33 @@
 		sp->vcl = NULL;
 	}
 
+	SES_Charge(sp);
+
 	sp->t_end = TIM_real();
 	sp->wrk->lastused = sp->t_end;
 	if (sp->xid == 0) {
 		sp->t_req = sp->t_end;
 		sp->t_resp = sp->t_end;
-	} else {
+	} else if (sp->esis == 0) {
 		dp = sp->t_resp - sp->t_req;
 		da = sp->t_end - sp->t_resp;
 		dh = sp->t_req - sp->t_open;
+		/* XXX: Add StatReq == StatSess */
 		WSP(sp, SLT_Length, "%u", sp->acct_req.bodybytes);
 		WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f",
 		    sp->xid, sp->t_req, sp->t_end, dh, dp, da);
 	}
-
 	sp->xid = 0;
 	sp->t_open = sp->t_end;
 	sp->t_resp = NAN;
 	WSL_Flush(sp->wrk, 0);
 
 	/* If we did an ESI include, don't mess up our state */
-	if (sp->esis > 0) {
-		SES_Charge(sp);
+	if (sp->esis > 0) 
 		return (1);
-	}
 
+	memset(&sp->acct_req, 0, sizeof sp->acct_req);
+
 	sp->t_req = NAN;
 
 	if (sp->fd >= 0 && sp->doclose != NULL) {
@@ -276,8 +278,6 @@
 		vca_close_session(sp, sp->doclose);
 	}
 
-	SES_Charge(sp);
-
 	if (sp->fd < 0) {
 		sp->wrk->stats.sess_closed++;
 		sp->wrk = NULL;
@@ -647,7 +647,7 @@
 		AN(sp->obj->ban);
 		HSH_Unbusy(sp);
 	}
-	sp->acct_req.fetch++;
+	sp->acct_tmp.fetch++;
 	sp->wrk->bereq = NULL;
 	sp->wrk->beresp = NULL;
 	sp->wrk->beresp1 = NULL;
@@ -679,7 +679,7 @@
 	/* Receive a HTTP protocol request */
 	HTC_Init(sp->htc, sp->ws, sp->fd);
 	sp->wrk->lastused = sp->t_open;
-	sp->acct_req.sess++;
+	sp->acct_tmp.sess++;
 
 	sp->step = STP_WAIT;
 	return (0);
@@ -946,7 +946,7 @@
 		return (0);
 	}
 	assert(sp->handling == VCL_RET_PASS);
-	sp->acct_req.pass++;
+	sp->acct_tmp.pass++;
 	sp->sendbody = 1;
 	sp->step = STP_FETCH;
 	return (0);
@@ -984,7 +984,7 @@
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
 
-	sp->acct_req.pipe++;
+	sp->acct_tmp.pipe++;
 	WS_Reset(sp->wrk->ws, NULL);
 	sp->wrk->bereq = sp->wrk->http[0];
 	http_Setup(sp->wrk->bereq, sp->wrk->ws);
@@ -1108,7 +1108,7 @@
 	sp->wrk->stats.client_req++;
 	sp->t_req = TIM_real();
 	sp->wrk->lastused = sp->t_req;
-	sp->acct_req.req++;
+	sp->acct_tmp.req++;
 
 	/* Assign XID and log */
 	sp->xid = ++xids;				/* XXX not locked */

Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.c	2010-06-28 11:53:33 UTC (rev 4988)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.c	2010-06-28 14:28:36 UTC (rev 4989)
@@ -859,6 +859,7 @@
 	char *ws_wm;
 	struct http http_save;
 	struct esidata *ed;
+	unsigned sxid;
 
 	w = sp->wrk;
 	WRW_Reserve(w, &sp->fd);
@@ -869,7 +870,7 @@
 		if (Tlen(eb->verbatim)) {
 			if (sp->http->protover >= 1.1)
 				(void)WRW_Write(w, eb->chunk_length, -1);
-			sp->acct_req.bodybytes += WRW_Write(w,
+			sp->acct_tmp.bodybytes += WRW_Write(w,
 			    eb->verbatim.b, Tlen(eb->verbatim));
 			if (sp->http->protover >= 1.1)
 				(void)WRW_Write(w, "\r\n", -1);
@@ -919,6 +920,7 @@
 		/* Client content already taken care of */
 		http_Unset(sp->http, H_Content_Length);
 
+		sxid = sp->xid;
 		while (1) {
 			sp->wrk = w;
 			CNT_Session(sp);
@@ -929,6 +931,7 @@
 			DSL(0x20, SLT_Debug, sp->id, "loop waiting for ESI");
 			(void)usleep(10000);
 		}
+		sp->xid = sxid;
 		AN(sp->wrk);
 		assert(sp->step == STP_DONE);
 		sp->esis--;

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2010-06-28 11:53:33 UTC (rev 4988)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2010-06-28 14:28:36 UTC (rev 4989)
@@ -258,7 +258,7 @@
 
 		if (sp->esis == 0)
 			/* no headers for interior ESI includes */
-			sp->acct_req.hdrbytes +=
+			sp->acct_tmp.hdrbytes +=
 			    http_Write(sp->wrk, sp->wrk->resp, 1);
 
 		if (WRW_FlushRelease(sp->wrk)) {
@@ -283,7 +283,7 @@
 		    http_GetHdr(sp->http, H_Range, &r))
 			res_dorange(sp, r, &low, &high);
 
-		sp->acct_req.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
+		sp->acct_tmp.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
 	} else if (!sp->disable_esi &&
 	    sp->esis > 0 &&
 	    sp->http->protover >= 1.1 &&
@@ -329,7 +329,7 @@
 
 		ptr += len;
 
-		sp->acct_req.bodybytes += len;
+		sp->acct_tmp.bodybytes += len;
 #ifdef SENDFILE_WORKS
 		/*
 		 * XXX: the overhead of setting up sendfile is not

Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c	2010-06-28 11:53:33 UTC (rev 4988)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c	2010-06-28 14:28:36 UTC (rev 4989)
@@ -83,11 +83,12 @@
 void
 SES_Charge(struct sess *sp)
 {
-	struct acct *a = &sp->acct_req;
+	struct acct *a = &sp->acct_tmp;
 
-#define ACCT(foo)	\
+#define ACCT(foo)				\
 	sp->wrk->stats.s_##foo += a->foo;	\
-	sp->acct.foo += a->foo;		\
+	sp->acct_req.foo += a->foo;		\
+	sp->acct_ses.foo += a->foo;		\
 	a->foo = 0;
 #include "acct_fields.h"
 #undef ACCT
@@ -247,7 +248,7 @@
 void
 SES_Delete(struct sess *sp)
 {
-	struct acct *b = &sp->acct;
+	struct acct *b = &sp->acct_ses;
 	struct sessmem *sm;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);




More information about the varnish-commit mailing list