[master] d600ab8 Move acct_tmp to worker instead of session and report # gunziped bytes rather than storage size when we gunzip for delivery.
Poul-Henning Kamp
phk at varnish-cache.org
Thu Sep 1 10:39:24 CEST 2011
commit d600ab8745c72f08272250cdb86dd4254f3feacd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Sep 1 08:38:33 2011 +0000
Move acct_tmp to worker instead of session and report # gunziped
bytes rather than storage size when we gunzip for delivery.
Fixes #992
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 0509d99..43a0c41 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -353,6 +353,8 @@ struct worker {
#define RES_ESI_CHILD (1<<5)
#define RES_GUNZIP (1<<6)
+ /* Temporary accounting */
+ struct acct acct_tmp;
};
/* Work Request for worker thread ------------------------------------*/
@@ -601,7 +603,6 @@ struct sess {
struct sessmem *mem;
struct workreq workreq;
- struct acct acct_tmp;
struct acct acct_req;
struct acct acct_ses;
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 0f69861..a4e5051 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -869,7 +869,7 @@ cnt_fetchbody(struct sess *sp)
AN(sp->obj->objcore->ban);
HSH_Unbusy(sp);
}
- sp->acct_tmp.fetch++;
+ sp->wrk->acct_tmp.fetch++;
sp->step = STP_PREPRESP;
return (0);
}
@@ -926,7 +926,7 @@ cnt_streambody(struct sess *sp)
} else {
sp->doclose = "Stream error";
}
- sp->acct_tmp.fetch++;
+ sp->wrk->acct_tmp.fetch++;
sp->director = NULL;
sp->restarts = 0;
@@ -968,7 +968,7 @@ cnt_first(struct sess *sp)
HTC_Init(sp->htc, sp->ws, sp->fd, params->http_req_size,
params->http_req_hdr_len);
sp->wrk->lastused = sp->t_open;
- sp->acct_tmp.sess++;
+ sp->wrk->acct_tmp.sess++;
sp->step = STP_WAIT;
return (0);
@@ -1272,7 +1272,7 @@ cnt_pass(struct sess *sp)
return (0);
}
assert(sp->handling == VCL_RET_PASS);
- sp->acct_tmp.pass++;
+ sp->wrk->acct_tmp.pass++;
sp->sendbody = 1;
sp->step = STP_FETCH;
return (0);
@@ -1310,7 +1310,7 @@ cnt_pipe(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
- sp->acct_tmp.pipe++;
+ sp->wrk->acct_tmp.pipe++;
WS_Reset(sp->wrk->ws, NULL);
http_Setup(sp->wrk->bereq, sp->wrk->ws);
http_FilterHeader(sp, HTTPH_R_PIPE);
@@ -1459,7 +1459,7 @@ cnt_start(struct sess *sp)
sp->wrk->stats.client_req++;
sp->t_req = TIM_real();
sp->wrk->lastused = sp->t_req;
- sp->acct_tmp.req++;
+ sp->wrk->acct_tmp.req++;
/* Assign XID and log */
sp->xid = ++xids; /* XXX not locked */
@@ -1614,6 +1614,9 @@ CNT_Session(struct sess *sp)
AZ(w->is_gunzip);
AZ(w->do_gunzip);
AZ(w->do_esi);
+#define ACCT(foo) AZ(w->acct_tmp.foo);
+#include "acct_fields.h"
+#undef ACCT
assert(WRW_IsReleased(w));
}
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index 40a8bdf..bed3104 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -378,6 +378,7 @@ VGZ_WrwGunzip(const struct sess *sp, struct vgz *vg, const void *ibuf,
return (-1);
}
if (obufl == *obufp || i == VGZ_STUCK) {
+ sp->wrk->acct_tmp.bodybytes += *obufp;
(void)WRW_Write(sp->wrk, obuf, *obufp);
(void)WRW_Flush(sp->wrk);
*obufp = 0;
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 17d1525..c592909 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -175,7 +175,6 @@ res_WriteGunzipObj(struct sess *sp)
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
u += st->len;
- sp->acct_tmp.bodybytes += st->len; /* XXX ? */
VSC_C_main->n_objwrite++;
i = VGZ_WrwGunzip(sp, vg,
@@ -195,7 +194,7 @@ res_WriteGunzipObj(struct sess *sp)
/*--------------------------------------------------------------------*/
static void
-res_WriteDirObj(struct sess *sp, ssize_t low, ssize_t high)
+res_WriteDirObj(const struct sess *sp, ssize_t low, ssize_t high)
{
ssize_t u = 0;
size_t ptr, off, len;
@@ -227,7 +226,7 @@ res_WriteDirObj(struct sess *sp, ssize_t low, ssize_t high)
ptr += len;
- sp->acct_tmp.bodybytes += len;
+ sp->wrk->acct_tmp.bodybytes += len;
#ifdef SENDFILE_WORKS
/*
* XXX: the overhead of setting up sendfile is not
@@ -292,7 +291,7 @@ RES_WriteObj(struct sess *sp)
* Send HTTP protocol header, unless interior ESI object
*/
if (!(sp->wrk->res_mode & RES_ESI_CHILD))
- sp->acct_tmp.hdrbytes +=
+ sp->wrk->acct_tmp.hdrbytes +=
http_Write(sp->wrk, sp->wrk->resp, 1);
if (!sp->wantbody)
@@ -348,7 +347,7 @@ RES_StreamStart(struct sess *sp)
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
"Content-Length: %s", sp->wrk->h_content_length);
- sp->acct_tmp.hdrbytes +=
+ sp->wrk->acct_tmp.hdrbytes +=
http_Write(sp->wrk, sp->wrk->resp, 1);
if (sp->wrk->res_mode & RES_CHUNKED)
diff --git a/bin/varnishd/cache_session.c b/bin/varnishd/cache_session.c
index af422a6..1ebca44 100644
--- a/bin/varnishd/cache_session.c
+++ b/bin/varnishd/cache_session.c
@@ -80,7 +80,7 @@ static struct lock stat_mtx;
void
SES_Charge(struct sess *sp)
{
- struct acct *a = &sp->acct_tmp;
+ struct acct *a = &sp->wrk->acct_tmp;
#define ACCT(foo) \
sp->wrk->stats.s_##foo += a->foo; \
More information about the varnish-commit
mailing list