[master] c34f10e Move the temporary accounting structure from wrk to req and eliminate two SES_Charge() calls that have nothing to charge.
Poul-Henning Kamp
phk at varnish-cache.org
Wed Jul 18 23:27:05 CEST 2012
commit c34f10e1213ae4df0db74d6f0477140cfa047aea
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jul 18 21:26:16 2012 +0000
Move the temporary accounting structure from wrk to req and
eliminate two SES_Charge() calls that have nothing to charge.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 63a7c3d..dfc8f69 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -344,8 +344,6 @@ struct worker {
struct vxid_pool vxid_pool;
- /* Temporary accounting */
- struct acct acct_tmp;
};
/* LRU ---------------------------------------------------------------*/
@@ -661,6 +659,8 @@ struct req {
/* Transaction VSL buffer */
struct vsl_log vsl[1];
+ /* Temporary accounting */
+ struct acct acct_req;
};
/*--------------------------------------------------------------------
@@ -821,9 +821,9 @@ int VGZ_Destroy(struct vgz **);
void VGZ_UpdateObj(const struct vgz*, struct object *);
int VGZ_WrwInit(struct vgz *vg);
-int VGZ_WrwGunzip(struct worker *w, struct vgz *, const void *ibuf,
+int VGZ_WrwGunzip(struct req *, struct vgz *, const void *ibuf,
ssize_t ibufl);
-void VGZ_WrwFlush(struct worker *wrk, struct vgz *vg);
+void VGZ_WrwFlush(struct req *, struct vgz *vg);
/* Return values */
#define VGZ_ERROR -1
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index d98d490..1fcaff4 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -161,7 +161,6 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req)
if (when < now || tmo == 0) {
sp->t_rx = NAN;
wrk->stats.sess_herd++;
- SES_Charge(wrk, req);
SES_ReleaseReq(req);
WAIT_Enter(sp);
return (1);
@@ -176,7 +175,6 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req)
}
}
}
- SES_Charge(wrk, req);
AZ(req->vcl);
SES_ReleaseReq(req);
SES_Delete(sp, why, now);
@@ -659,7 +657,7 @@ cnt_fetch(struct worker *wrk, struct req *req)
need_host_hdr = !http_GetHdr(bo->bereq, H_Host, NULL);
- wrk->acct_tmp.fetch++;
+ req->acct_req.fetch++;
i = FetchHdr(req, need_host_hdr, req->objcore->objhead == NULL);
/*
@@ -1264,7 +1262,7 @@ cnt_pass(struct worker *wrk, struct req *req)
return (0);
}
assert(req->handling == VCL_RET_PASS);
- wrk->acct_tmp.pass++;
+ req->acct_req.pass++;
req->req_step = R_STP_FETCH;
req->objcore = HSH_NewObjCore(wrk);
@@ -1307,7 +1305,7 @@ cnt_pipe(struct worker *wrk, struct req *req)
CHECK_OBJ_NOTNULL(req->vcl, VCL_CONF_MAGIC);
AZ(req->busyobj);
- wrk->acct_tmp.pipe++;
+ req->acct_req.pipe++;
req->busyobj = VBO_GetBusyObj(wrk);
bo = req->busyobj;
bo->vsl->wid = req->sp->vsl_id;
@@ -1486,7 +1484,7 @@ cnt_start(struct worker *wrk, struct req *req)
/* Update stats of various sorts */
wrk->stats.client_req++;
- wrk->acct_tmp.req++;
+ req->acct_req.req++;
/* Assign XID and log */
req->xid = ++xids; /* XXX not locked */
@@ -1600,8 +1598,10 @@ CNT_Request(struct worker *wrk, struct req *req)
WS_Assert(wrk->aws);
CHECK_OBJ_ORNULL(wrk->nobjhead, OBJHEAD_MAGIC);
}
- if (done == 1)
+ if (done == 1) {
+ /* done == 2 was charged by cache_hash.c */
SES_Charge(wrk, req);
+ }
req->wrk = NULL;
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index cc722ce..a6e5f11 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -321,7 +321,7 @@ ESI_Deliver(struct req *req)
* response
*/
AN(vgz);
- i = VGZ_WrwGunzip(req->wrk, vgz,
+ i = VGZ_WrwGunzip(req, vgz,
st->ptr + off, l2);
if (WRW_Error(req->wrk)) {
SES_Close(req->sp,
@@ -374,7 +374,7 @@ ESI_Deliver(struct req *req)
r = (void*)strchr((const char*)q, '\0');
AN(r);
if (vgz != NULL)
- VGZ_WrwFlush(req->wrk, vgz);
+ VGZ_WrwFlush(req, vgz);
if (WRW_Flush(req->wrk)) {
SES_Close(req->sp, SC_REM_CLOSE);
p = e;
@@ -391,7 +391,7 @@ ESI_Deliver(struct req *req)
}
}
if (vgz != NULL) {
- VGZ_WrwFlush(req->wrk, vgz);
+ VGZ_WrwFlush(req, vgz);
(void)VGZ_Destroy(&vgz);
}
if (req->gzip_resp && req->esi_level == 0) {
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 1ebabb0..aed84d9 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -315,13 +315,16 @@ VGZ_WrwInit(struct vgz *vg)
*/
int
-VGZ_WrwGunzip(struct worker *wrk, struct vgz *vg, const void *ibuf,
+VGZ_WrwGunzip(struct req *req, struct vgz *vg, const void *ibuf,
ssize_t ibufl)
{
int i;
size_t dl;
const void *dp;
+ struct worker *wrk;
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ wrk = req->wrk;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
AN(vg->m_buf);
@@ -340,7 +343,7 @@ VGZ_WrwGunzip(struct worker *wrk, struct vgz *vg, const void *ibuf,
return (-1);
}
if (vg->m_len == vg->m_sz || i == VGZ_STUCK) {
- wrk->acct_tmp.bodybytes += vg->m_len;
+ req->acct_req.bodybytes += vg->m_len;
(void)WRW_Write(wrk, vg->m_buf, vg->m_len);
(void)WRW_Flush(wrk);
vg->m_len = 0;
@@ -355,15 +358,19 @@ VGZ_WrwGunzip(struct worker *wrk, struct vgz *vg, const void *ibuf,
/*--------------------------------------------------------------------*/
void
-VGZ_WrwFlush(struct worker *wrk, struct vgz *vg)
+VGZ_WrwFlush(struct req *req, struct vgz *vg)
{
+ struct worker *wrk;
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ wrk = req->wrk;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
if (vg->m_len == 0)
return;
- wrk->acct_tmp.bodybytes += vg->m_len;
+ req->acct_req.bodybytes += vg->m_len;
(void)WRW_Write(wrk, vg->m_buf, vg->m_len);
(void)WRW_Flush(wrk);
vg->m_len = 0;
diff --git a/bin/varnishd/cache/cache_pipe.c b/bin/varnishd/cache/cache_pipe.c
index 238d0a3..f13bbcc 100644
--- a/bin/varnishd/cache/cache_pipe.c
+++ b/bin/varnishd/cache/cache_pipe.c
@@ -82,10 +82,10 @@ PipeRequest(struct req *req)
(void)VTCP_blocking(vc->fd);
WRW_Reserve(wrk, &vc->fd, bo->vsl, req->t_req);
- wrk->acct_tmp.hdrbytes += http_Write(wrk, bo->bereq, 0);
+ req->acct_req.hdrbytes += http_Write(wrk, bo->bereq, 0);
if (req->htc->pipeline.b != NULL)
- wrk->acct_tmp.bodybytes +=
+ req->acct_req.bodybytes +=
WRW_Write(wrk, req->htc->pipeline.b,
Tlen(req->htc->pipeline));
diff --git a/bin/varnishd/cache/cache_response.c b/bin/varnishd/cache/cache_response.c
index e82ab67..fda117d 100644
--- a/bin/varnishd/cache/cache_response.c
+++ b/bin/varnishd/cache/cache_response.c
@@ -171,11 +171,11 @@ res_WriteGunzipObj(struct req *req)
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
u += st->len;
- i = VGZ_WrwGunzip(req->wrk, vg, st->ptr, st->len);
+ i = VGZ_WrwGunzip(req, vg, st->ptr, st->len);
/* XXX: error check */
(void)i;
}
- VGZ_WrwFlush(req->wrk, vg);
+ VGZ_WrwFlush(req, vg);
(void)VGZ_Destroy(&vg);
assert(u == req->obj->len);
}
@@ -183,7 +183,7 @@ res_WriteGunzipObj(struct req *req)
/*--------------------------------------------------------------------*/
static void
-res_WriteDirObj(const struct req *req, ssize_t low, ssize_t high)
+res_WriteDirObj(struct req *req, ssize_t low, ssize_t high)
{
ssize_t u = 0;
size_t ptr, off, len;
@@ -215,7 +215,7 @@ res_WriteDirObj(const struct req *req, ssize_t low, ssize_t high)
ptr += len;
- req->wrk->acct_tmp.bodybytes += len;
+ req->acct_req.bodybytes += len;
(void)WRW_Write(req->wrk, st->ptr + off, len);
}
assert(u == req->obj->len);
@@ -254,7 +254,7 @@ RES_WriteObj(struct req *req)
* Send HTTP protocol header, unless interior ESI object
*/
if (!(req->res_mode & RES_ESI_CHILD))
- req->wrk->acct_tmp.hdrbytes +=
+ req->acct_req.hdrbytes +=
http_Write(req->wrk, req->resp, 1);
if (!req->wantbody)
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index d2cca4b..5e994f7 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -79,7 +79,7 @@ SES_Charge(struct worker *wrk, struct req *req)
sp = req->sp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- a = &wrk->acct_tmp;
+ a = &req->acct_req;
req->req_bodybytes += a->bodybytes;
#define ACCT(foo) \
@@ -229,7 +229,7 @@ SES_pool_accept_task(struct worker *wrk, void *arg)
VCA_FailSess(wrk);
return;
}
- wrk->acct_tmp.sess++;
+ wrk->stats.s_sess++;
sp->t_open = VTIM_real();
sp->t_rx = sp->t_open;
@@ -431,6 +431,9 @@ SES_ReleaseReq(struct req *req)
struct sesspool *pp;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+#define ACCT(foo) AZ(req->acct_req.foo);
+#include "tbl/acct_fields.h"
+#undef ACCT
sp = req->sp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
pp = sp->sesspool;
diff --git a/include/tbl/acct_fields.h b/include/tbl/acct_fields.h
index 154f106..3dc1ff6 100644
--- a/include/tbl/acct_fields.h
+++ b/include/tbl/acct_fields.h
@@ -26,12 +26,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * These are the stats we keep track of per session. They will be summed,
- * via the sp->wrk->stats into the s_<name> fields in the SHM file.
+ * These are the stats we keep track of per session.
+ * SES_Charge() sums them into wrk->stats
* NB: Remember to mark those in vsc_fields.h to be included in struct dstat.
*/
-ACCT(sess)
ACCT(req)
ACCT(pipe)
ACCT(pass)
More information about the varnish-commit
mailing list