]> err.no Git - varnish/commitdiff
Eliminate redundant args from stevedore->send()
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 22 Jul 2006 21:20:08 +0000 (21:20 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 22 Jul 2006 21:20:08 +0000 (21:20 +0000)
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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/cache_pass.c
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/cache_response.c
varnish-cache/bin/varnishd/stevedore.h
varnish-cache/bin/varnishd/storage_file.c
varnish-cache/bin/varnishd/storage_malloc.c

index 48cf9b63a567df4e939943bf82910da0a74b5660..1d7a0b2e84fa6587174bf99eacc9db1c6a4c6902 100644 (file)
@@ -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);
index f967afe6a80e166144b8c96588a8278c571aff82..28849c221686c436c328de219ff5231580882682 100644 (file)
@@ -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);
index 5bcd6576872495369f1dd3f66b9e6c37bfd14169..d9de232993181263384c56aebabe5d6038a9ec5f 100644 (file)
@@ -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);
 }
 
 /*--------------------------------------------------------------------*/
index 0fc65a799135a18b553450708dfa198161987f63..62440fe0b4864e284be7e744d386dd990bd33e10 100644 (file)
@@ -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"))
index 1ed8f565b3a20df5e7069a3518760f12561d6f79..601ef47cd1898ae67d1ce382c8519ebcd81cfad7 100644 (file)
@@ -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);
 }
 
 /*--------------------------------------------------------------------*/
index 107ae74f7c063106e1ca3e8b792c04c9a9364768..5311ddf5f4f7736742e24cb2ac6c8c012f6146cf 100644 (file)
@@ -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);
        }
index fbb9afe9c324df9b811a7a4883ef2e1aef87dbb8..89548e81cceff5510daf52c855a3caba63729a4b 100644 (file)
@@ -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;
index 494d2351663054a5200c890f71c2aef3c7cafe08..58fbb00eabc3e6ad239c2813864a8b9136efd584 100644 (file)
@@ -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
index 5f1af5beb0d0c0e8f2f70aabcf2cef7d56d57e82..2794c8e90f9e74fae524b56a98f3aa01a2d986ae 100644 (file)
@@ -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
 };