Commit 4b04e373 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fix a problem with accounting of ESI transactions, in particular make

the Length header match the actual composite object sent to the client.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4989 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 198f2b02
......@@ -434,8 +434,9 @@ struct sess {
struct sessmem *mem;
struct workreq workreq;
struct acct acct;
struct acct acct_tmp;
struct acct acct_req;
struct acct acct_ses;
#if defined(HAVE_EPOLL_CTL)
struct epoll_event ev;
......
......@@ -176,7 +176,7 @@ VCA_Prep(struct sess *sp)
VSL(SLT_SessionOpen, sp->fd, "%s %s %s",
sp->addr, sp->port, sp->mylsock->name);
}
sp->acct.first = sp->t_open;
sp->acct_ses.first = sp->t_open;
if (need_test)
sock_test(sp->fd);
if (need_linger)
......
......@@ -240,30 +240,32 @@ cnt_done(struct sess *sp)
sp->vcl = NULL;
}
SES_Charge(sp);
sp->t_end = TIM_real();
sp->wrk->lastused = sp->t_end;
if (sp->xid == 0) {
sp->t_req = sp->t_end;
sp->t_resp = sp->t_end;
} else {
} else if (sp->esis == 0) {
dp = sp->t_resp - sp->t_req;
da = sp->t_end - sp->t_resp;
dh = sp->t_req - sp->t_open;
/* XXX: Add StatReq == StatSess */
WSP(sp, SLT_Length, "%u", sp->acct_req.bodybytes);
WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f",
sp->xid, sp->t_req, sp->t_end, dh, dp, da);
}
sp->xid = 0;
sp->t_open = sp->t_end;
sp->t_resp = NAN;
WSL_Flush(sp->wrk, 0);
/* If we did an ESI include, don't mess up our state */
if (sp->esis > 0) {
SES_Charge(sp);
if (sp->esis > 0)
return (1);
}
memset(&sp->acct_req, 0, sizeof sp->acct_req);
sp->t_req = NAN;
......@@ -276,8 +278,6 @@ cnt_done(struct sess *sp)
vca_close_session(sp, sp->doclose);
}
SES_Charge(sp);
if (sp->fd < 0) {
sp->wrk->stats.sess_closed++;
sp->wrk = NULL;
......@@ -647,7 +647,7 @@ cnt_fetch(struct sess *sp)
AN(sp->obj->ban);
HSH_Unbusy(sp);
}
sp->acct_req.fetch++;
sp->acct_tmp.fetch++;
sp->wrk->bereq = NULL;
sp->wrk->beresp = NULL;
sp->wrk->beresp1 = NULL;
......@@ -679,7 +679,7 @@ cnt_first(struct sess *sp)
/* Receive a HTTP protocol request */
HTC_Init(sp->htc, sp->ws, sp->fd);
sp->wrk->lastused = sp->t_open;
sp->acct_req.sess++;
sp->acct_tmp.sess++;
sp->step = STP_WAIT;
return (0);
......@@ -946,7 +946,7 @@ cnt_pass(struct sess *sp)
return (0);
}
assert(sp->handling == VCL_RET_PASS);
sp->acct_req.pass++;
sp->acct_tmp.pass++;
sp->sendbody = 1;
sp->step = STP_FETCH;
return (0);
......@@ -984,7 +984,7 @@ cnt_pipe(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
sp->acct_req.pipe++;
sp->acct_tmp.pipe++;
WS_Reset(sp->wrk->ws, NULL);
sp->wrk->bereq = sp->wrk->http[0];
http_Setup(sp->wrk->bereq, sp->wrk->ws);
......@@ -1108,7 +1108,7 @@ cnt_start(struct sess *sp)
sp->wrk->stats.client_req++;
sp->t_req = TIM_real();
sp->wrk->lastused = sp->t_req;
sp->acct_req.req++;
sp->acct_tmp.req++;
/* Assign XID and log */
sp->xid = ++xids; /* XXX not locked */
......
......@@ -859,6 +859,7 @@ ESI_Deliver(struct sess *sp)
char *ws_wm;
struct http http_save;
struct esidata *ed;
unsigned sxid;
w = sp->wrk;
WRW_Reserve(w, &sp->fd);
......@@ -869,7 +870,7 @@ ESI_Deliver(struct sess *sp)
if (Tlen(eb->verbatim)) {
if (sp->http->protover >= 1.1)
(void)WRW_Write(w, eb->chunk_length, -1);
sp->acct_req.bodybytes += WRW_Write(w,
sp->acct_tmp.bodybytes += WRW_Write(w,
eb->verbatim.b, Tlen(eb->verbatim));
if (sp->http->protover >= 1.1)
(void)WRW_Write(w, "\r\n", -1);
......@@ -919,6 +920,7 @@ ESI_Deliver(struct sess *sp)
/* Client content already taken care of */
http_Unset(sp->http, H_Content_Length);
sxid = sp->xid;
while (1) {
sp->wrk = w;
CNT_Session(sp);
......@@ -929,6 +931,7 @@ ESI_Deliver(struct sess *sp)
DSL(0x20, SLT_Debug, sp->id, "loop waiting for ESI");
(void)usleep(10000);
}
sp->xid = sxid;
AN(sp->wrk);
assert(sp->step == STP_DONE);
sp->esis--;
......
......@@ -258,7 +258,7 @@ RES_WriteObj(struct sess *sp)
if (sp->esis == 0)
/* no headers for interior ESI includes */
sp->acct_req.hdrbytes +=
sp->acct_tmp.hdrbytes +=
http_Write(sp->wrk, sp->wrk->resp, 1);
if (WRW_FlushRelease(sp->wrk)) {
......@@ -283,7 +283,7 @@ RES_WriteObj(struct sess *sp)
http_GetHdr(sp->http, H_Range, &r))
res_dorange(sp, r, &low, &high);
sp->acct_req.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
sp->acct_tmp.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1);
} else if (!sp->disable_esi &&
sp->esis > 0 &&
sp->http->protover >= 1.1 &&
......@@ -329,7 +329,7 @@ RES_WriteObj(struct sess *sp)
ptr += len;
sp->acct_req.bodybytes += len;
sp->acct_tmp.bodybytes += len;
#ifdef SENDFILE_WORKS
/*
* XXX: the overhead of setting up sendfile is not
......
......@@ -83,11 +83,12 @@ static struct lock stat_mtx;
void
SES_Charge(struct sess *sp)
{
struct acct *a = &sp->acct_req;
struct acct *a = &sp->acct_tmp;
#define ACCT(foo) \
#define ACCT(foo) \
sp->wrk->stats.s_##foo += a->foo; \
sp->acct.foo += a->foo; \
sp->acct_req.foo += a->foo; \
sp->acct_ses.foo += a->foo; \
a->foo = 0;
#include "acct_fields.h"
#undef ACCT
......@@ -247,7 +248,7 @@ SES_Alloc(void)
void
SES_Delete(struct sess *sp)
{
struct acct *b = &sp->acct;
struct acct *b = &sp->acct_ses;
struct sessmem *sm;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment