From: phk Date: Sat, 22 Jul 2006 21:20:08 +0000 (+0000) Subject: Eliminate redundant args from stevedore->send() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c0d57c05fe23c3a8e47d22e9997a03de7e28204;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@565 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 48cf9b63..1d7a0b2e 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -322,7 +322,7 @@ void HSH_Init(void); /* 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 @@ int http_DissectResponse(struct http *sp, int fd); /* 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_Init(void); 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); diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index f967afe6..28849c22 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -191,6 +191,7 @@ cnt_fetch(struct sess *sp) 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 @@ DOT passbody -> DONE 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 @@ static int cnt_pipe(struct sess *sp) { + sp->wrk->acct.pipe++; PipeSession(sp); sp->step = STP_DONE; return (0); @@ -515,6 +519,7 @@ cnt_recv(struct sess *sp) assert(sp->obj == NULL); + sp->wrk->acct.req++; done = http_DissectRequest(sp->http, sp->fd); if (done != 0) { RES_Error(sp, done, NULL); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 5bcd6576..d9de2329 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -635,28 +635,29 @@ http_PrintfHeader(int fd, struct http *to, const char *fmt, ...) /*--------------------------------------------------------------------*/ -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); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index 0fc65a79..62440fe0 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -46,7 +46,7 @@ pass_straight(struct sess *sp, int fd, struct http *hp, char *bi) 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 @@ pass_chunked(struct sess *sp, int fd, struct http *hp) 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 @@ pass_chunked(struct sess *sp, int fd, struct http *hp) } 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 @@ pass_chunked(struct sess *sp, int fd, struct http *hp) 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 @@ pass_chunked(struct sess *sp, int fd, struct http *hp) /*--------------------------------------------------------------------*/ void -PassBody(struct worker *w, struct sess *sp) +PassBody(struct sess *sp) { struct vbe_conn *vc; char *b; @@ -152,8 +153,8 @@ PassBody(struct worker *w, struct sess *sp) 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 @@ PassBody(struct worker *w, struct sess *sp) 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")) diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 1ed8f565..601ef47c 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -60,27 +60,29 @@ WRK_Flush(struct worker *w) 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 @@ WRK_Write(struct worker *w, const void *ptr, int len) w->iov[w->niov].iov_base = (void*)(uintptr_t)ptr; w->iov[w->niov++].iov_len = len; w->liov += len; + return (len); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 107ae74f..5311ddf5 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -159,21 +159,21 @@ RES_WriteObj(struct sess *sp) 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); } diff --git a/varnish-cache/bin/varnishd/stevedore.h b/varnish-cache/bin/varnishd/stevedore.h index fbb9afe9..89548e81 100644 --- a/varnish-cache/bin/varnishd/stevedore.h +++ b/varnish-cache/bin/varnishd/stevedore.h @@ -11,7 +11,7 @@ typedef void storage_open_f(struct stevedore *); 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; diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index 494d2351..58fbb00e 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -555,7 +555,7 @@ smf_free(struct storage *s) /*--------------------------------------------------------------------*/ 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_send(struct storage *st, struct sess *sp, struct iovec *iov, int niov, size_ 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 diff --git a/varnish-cache/bin/varnishd/storage_malloc.c b/varnish-cache/bin/varnishd/storage_malloc.c index 5f1af5be..2794c8e9 100644 --- a/varnish-cache/bin/varnishd/storage_malloc.c +++ b/varnish-cache/bin/varnishd/storage_malloc.c @@ -39,10 +39,7 @@ sma_free(struct storage *s) } struct stevedore sma_stevedore = { - "malloc", - NULL, /* init */ - NULL, /* open */ - sma_alloc, - NULL, /* trim */ - sma_free + .name = "malloc", + .alloc = sma_alloc, + .free = sma_free };