Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Merge r4989: Fix a problem with accounting of ESI transactions
Browse files Browse the repository at this point in the history
In particular make the Length header match the actual composite object
sent to the client.



git-svn-id: http://www.varnish-cache.org/svn/branches/2.1@5029 d4fa192b-c00b-0410-8231-f00ffab90ce4
  • Loading branch information
Tollef Fog Heen committed Jul 6, 2010
1 parent a7619d3 commit 0103bd6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion bin/varnishd/cache.h
Expand Up @@ -430,8 +430,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;
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache_acceptor.c
Expand Up @@ -177,7 +177,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)
Expand Down
24 changes: 12 additions & 12 deletions bin/varnishd/cache_center.c
Expand Up @@ -241,30 +241,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;

Expand All @@ -277,8 +279,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;
Expand Down Expand Up @@ -648,7 +648,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;
Expand Down Expand Up @@ -680,7 +680,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);
Expand Down Expand Up @@ -947,7 +947,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);
Expand Down Expand Up @@ -985,7 +985,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);
Expand Down Expand Up @@ -1109,7 +1109,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 */
Expand Down
5 changes: 4 additions & 1 deletion bin/varnishd/cache_esi.c
Expand Up @@ -863,6 +863,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);
Expand All @@ -873,7 +874,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);
Expand Down Expand Up @@ -923,6 +924,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);
Expand All @@ -933,6 +935,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--;
Expand Down
6 changes: 3 additions & 3 deletions bin/varnishd/cache_response.c
Expand Up @@ -259,7 +259,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)) {
Expand All @@ -284,7 +284,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 &&
Expand Down Expand Up @@ -330,7 +330,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
Expand Down
9 changes: 5 additions & 4 deletions bin/varnishd/cache_session.c
Expand Up @@ -84,11 +84,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
Expand Down Expand Up @@ -248,7 +249,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);
Expand Down

0 comments on commit 0103bd6

Please sign in to comment.