r565 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Sat Jul 22 23:20:08 CEST 2006


Author: phk
Date: 2006-07-22 23:20:08 +0200 (Sat, 22 Jul 2006)
New Revision: 565

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_pass.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishd/storage_file.c
   trunk/varnish-cache/bin/varnishd/storage_malloc.c
Log:
Eliminate redundant args from stevedore->send()

Have WRK_Write() and friends return number of bytes (we can't use
WRK_Flush() as that may act on both header and body).

Collect more stats.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-22 21:20:08 UTC (rev 565)
@@ -322,7 +322,7 @@
 /* cache_http.c */
 void HTTP_Init(void);
 void http_CopyHttp(struct http *to, struct http *fm);
-void http_Write(struct worker *w, struct http *hp, int resp);
+unsigned http_Write(struct worker *w, struct http *hp, int resp);
 void http_GetReq(int fd, struct http *to, struct http *fm);
 void http_CopyReq(int fd, struct http *to, struct http *fm);
 void http_CopyResp(int fd, struct http *to, struct http *fm);
@@ -346,7 +346,7 @@
 
 /* cache_pass.c */
 void PassSession(struct sess *sp);
-void PassBody(struct worker *w, struct sess *sp);
+void PassBody(struct sess *sp);
 
 /* cache_pipe.c */
 void PipeSession(struct sess *sp);
@@ -356,8 +356,8 @@
 void WRK_QueueSession(struct sess *sp);
 void WRK_Reset(struct worker *w, int *fd);
 int WRK_Flush(struct worker *w);
-void WRK_Write(struct worker *w, const void *ptr, int len);
-void WRK_WriteH(struct worker *w, struct http_hdr *hh, const char *suf);
+unsigned WRK_Write(struct worker *w, const void *ptr, int len);
+unsigned WRK_WriteH(struct worker *w, struct http_hdr *hh, const char *suf);
 
 /* cache_session.c [SES] */
 void SES_Init(void);

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2006-07-22 21:20:08 UTC (rev 565)
@@ -191,6 +191,7 @@
 		FetchBody(sp);
 		HSH_Ref(sp->obj); /* get another, STP_DELIVER will deref */
 		HSH_Unbusy(sp->obj);
+		sp->wrk->acct.fetch++;
 		sp->step = STP_DELIVER;
 		return (0);
 	}
@@ -448,7 +449,9 @@
 static int
 cnt_passbody(struct sess *sp)
 {
-	PassBody(sp->wrk, sp);
+
+	sp->wrk->acct.pass++;
+	PassBody(sp);
 	sp->step = STP_DONE;
 	return (0);
 }
@@ -472,6 +475,7 @@
 cnt_pipe(struct sess *sp)
 {
 
+	sp->wrk->acct.pipe++;
 	PipeSession(sp);
 	sp->step = STP_DONE;
 	return (0);
@@ -515,6 +519,7 @@
 
 	assert(sp->obj == NULL);
 
+	sp->wrk->acct.req++;
 	done = http_DissectRequest(sp->http, sp->fd);
 	if (done != 0) {
 		RES_Error(sp, done, NULL);

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-22 21:20:08 UTC (rev 565)
@@ -635,28 +635,29 @@
 
 /*--------------------------------------------------------------------*/
 
-void
+unsigned
 http_Write(struct worker *w, struct http *hp, int resp)
 {
-	unsigned u;
+	unsigned u, l;
 
 	if (resp) {
 		assert(hp->hd[HTTP_HDR_STATUS].b != NULL);
-		WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " ");
-		WRK_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " ");
-		WRK_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n");
+		l = WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " ");
+		l += WRK_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " ");
+		l += WRK_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n");
 	} else {
 		assert(hp->hd[HTTP_HDR_URL].b != NULL);
-		WRK_WriteH(w, &hp->hd[HTTP_HDR_REQ], " ");
-		WRK_WriteH(w, &hp->hd[HTTP_HDR_URL], " ");
-		WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], "\r\n");
+		l = WRK_WriteH(w, &hp->hd[HTTP_HDR_REQ], " ");
+		l += WRK_WriteH(w, &hp->hd[HTTP_HDR_URL], " ");
+		l += WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], "\r\n");
 	}
 	for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) {
 		assert(hp->hd[u].b != NULL);
 		assert(hp->hd[u].e != NULL);
-		WRK_WriteH(w, &hp->hd[u], "\r\n");
+		l += WRK_WriteH(w, &hp->hd[u], "\r\n");
 	}
-	WRK_Write(w, "\r\n", -1);
+	l += WRK_Write(w, "\r\n", -1);
+	return (l);
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-22 21:20:08 UTC (rev 565)
@@ -46,7 +46,7 @@
 		if (i == 0 && bi == NULL)
 			return (1);
 		assert(i > 0);
-		WRK_Write(sp->wrk, buf, i);
+		sp->wrk->acct.bodybytes += WRK_Write(sp->wrk, buf, i);
 		if (WRK_Flush(sp->wrk))
 			vca_close_session(sp, "remote closed");
 		cl -= i;
@@ -93,7 +93,7 @@
 		if (u == 0)
 			break;
 
-		WRK_Write(sp->wrk, p, q - p);
+		sp->wrk->acct.bodybytes += WRK_Write(sp->wrk, p, q - p);
 
 		p = q;
 
@@ -105,14 +105,15 @@
 			}
 			if (bp - p < j)
 				j = bp - p;
-			WRK_Write(sp->wrk, p, j);
+			sp->wrk->acct.bodybytes += WRK_Write(sp->wrk, p, j);
 			p += j;
 			u -= j;
 		}
 		while (u > 0) {
 			if (http_GetTail(hp, u, &b, &e)) {
 				j = e - b;
-				WRK_Write(sp->wrk, q, j);
+				sp->wrk->acct.bodybytes +=
+				    WRK_Write(sp->wrk, q, j);
 				u -= j;
 			} else
 				break;
@@ -125,7 +126,7 @@
 				j = sizeof buf;
 			i = read(fd, buf, j);
 			assert(i > 0);
-			WRK_Write(sp->wrk, buf, i);
+			sp->wrk->acct.bodybytes += WRK_Write(sp->wrk, buf, i);
 			u -= i;
 			if (WRK_Flush(sp->wrk))
 				vca_close_session(sp, "remote closed");
@@ -138,7 +139,7 @@
 /*--------------------------------------------------------------------*/
 
 void
-PassBody(struct worker *w, struct sess *sp)
+PassBody(struct sess *sp)
 {
 	struct vbe_conn *vc;
 	char *b;
@@ -152,8 +153,8 @@
 	http_CopyResp(sp->fd, sp->http, vc->http);
 	http_FilterHeader(sp->fd, sp->http, vc->http, HTTPH_A_PASS);
 	http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
-	WRK_Reset(w, &sp->fd);
-	http_Write(w, sp->http, 1);
+	WRK_Reset(sp->wrk, &sp->fd);
+	sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
 
 	if (http_GetHdr(vc->http, H_Content_Length, &b))
 		cls = pass_straight(sp, vc->fd, vc->http, b);
@@ -165,7 +166,7 @@
 		cls = pass_straight(sp, vc->fd, vc->http, NULL);
 	}
 
-	if (WRK_Flush(w))
+	if (WRK_Flush(sp->wrk))
 		vca_close_session(sp, "remote closed");
 
 	if (http_GetHdr(vc->http, H_Connection, &b) && !strcasecmp(b, "close"))

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-22 21:20:08 UTC (rev 565)
@@ -60,27 +60,29 @@
 	return (w->werr);
 }
 
-void
+unsigned
 WRK_WriteH(struct worker *w, struct http_hdr *hh, const char *suf)
 {
+	unsigned u;
 	
 	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
 	assert(w != NULL);
 	assert(hh != NULL);
 	assert(hh->b != NULL);
 	assert(hh->e != NULL);
-	WRK_Write(w, hh->b, hh->e - hh->b);
+	u = WRK_Write(w, hh->b, hh->e - hh->b);
 	if (suf != NULL)
-		WRK_Write(w, suf, -1);
+		u += WRK_Write(w, suf, -1);
+	return (u);
 }
 
-void
+unsigned
 WRK_Write(struct worker *w, const void *ptr, int len)
 {
 
 	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
 	if (len == 0 || *w->wfd < 0)
-		return;
+		return (0);
 	if (len == -1)
 		len = strlen(ptr);
 	if (w->niov == MAX_IOVS)
@@ -88,6 +90,7 @@
 	w->iov[w->niov].iov_base = (void*)(uintptr_t)ptr;
 	w->iov[w->niov++].iov_len = len;
 	w->liov += len;
+	return (len);
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2006-07-22 21:20:08 UTC (rev 565)
@@ -159,21 +159,21 @@
 	if (sp->doclose != NULL)
 		http_PrintfHeader(sp->fd, sp->http, "Connection: close");
 	WRK_Reset(sp->wrk, &sp->fd);
-	http_Write(sp->wrk, sp->http, 1);
+	sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
 	
 	/* XXX: conditional request handling */
 	if (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET")) {
 		TAILQ_FOREACH(st, &sp->obj->store, list) {
 			assert(st->stevedore != NULL);
 			u += st->len;
+			sp->wrk->acct.bodybytes += st->len;
 			if (st->stevedore->send == NULL) {
 				WRK_Write(sp->wrk, st->ptr, st->len);
-				continue;
+			} else {
+				st->stevedore->send(st, sp);
+				sp->wrk->niov = 0;
+				sp->wrk->liov = 0;
 			}
-			st->stevedore->send(st, sp,
-			    sp->wrk->iov, sp->wrk->niov, sp->wrk->liov);
-			sp->wrk->niov = 0;
-			sp->wrk->liov = 0;
 		}
 		assert(u == sp->obj->len);
 	}

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2006-07-22 21:20:08 UTC (rev 565)
@@ -11,7 +11,7 @@
 typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
 typedef void storage_trim_f(struct storage *, size_t size);
 typedef void storage_free_f(struct storage *);
-typedef void storage_send_f(struct storage *, struct sess *, struct iovec *, int niovec, size_t liovec);
+typedef void storage_send_f(struct storage *, struct sess *);
 
 struct stevedore {
 	const char		*name;

Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c	2006-07-22 21:20:08 UTC (rev 565)
@@ -555,7 +555,7 @@
 /*--------------------------------------------------------------------*/
 
 static void
-smf_send(struct storage *st, struct sess *sp, struct iovec *iov, int niov, size_t liov)
+smf_send(struct storage *st, struct sess *sp)
 {
 	struct smf *smf;
 	int i;
@@ -565,32 +565,33 @@
 	smf = st->priv;
 
 	memset(&sfh, 0, sizeof sfh);
-	sfh.headers = iov;
-	sfh.hdr_cnt = niov;
+	sfh.headers = sp->wrk->iov;
+	sfh.hdr_cnt = sp->wrk->niov;
 	i = sendfile(smf->sc->fd,
 	    sp->fd,
 	    smf->offset,
 	    st->len, &sfh, &sent, 0);
-	if (sent == st->len + liov)
+	if (sent == st->len + sp->wrk->liov)
 		return;
 	vca_close_session(sp, "remote closed");
 	if (errno == EPIPE || errno == ENOTCONN)
 		return;
 	VSL(SLT_Debug, sp->fd,
 	    "sent i=%d sent=%ju size=%ju liov=%ju errno=%d\n",
-	    i, (uintmax_t)sent, (uintmax_t)st->len, (uintmax_t)liov, errno);
+	    i, (uintmax_t)sent, (uintmax_t)st->len,
+	    (uintmax_t)sp->wrk->liov, errno);
 }
 
 /*--------------------------------------------------------------------*/
 
 struct stevedore smf_stevedore = {
-	"file",
-	smf_init,
-	smf_open,
-	smf_alloc,
-	smf_trim,
-	smf_free,
-	smf_send
+	.name =		"file",
+	.init =		smf_init,
+	.open =		smf_open,
+	.alloc =	smf_alloc,
+	.trim =		smf_trim,
+	.free =		smf_free,
+	.send =		smf_send
 };
 
 #ifdef INCLUDE_TEST_DRIVER

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c	2006-07-22 20:57:02 UTC (rev 564)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c	2006-07-22 21:20:08 UTC (rev 565)
@@ -39,10 +39,7 @@
 }
 
 struct stevedore sma_stevedore = {
-	"malloc",
-	NULL,			/* init */
-	NULL,			/* open */
-	sma_alloc,
-	NULL,			/* trim */
-	sma_free
+	.name =		"malloc",
+	.alloc =	sma_alloc,
+	.free =		sma_free
 };




More information about the varnish-commit mailing list