struct acct acct;
unsigned char wlog[WLOGSPACE];
unsigned char *wlp, *wle;
+ unsigned wlr;
};
struct workreq {
void http_ClrHeader(struct http *to);
void http_CopyHttp(struct http *to, struct http *fm);
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);
-void http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response);
-void http_FilterHeader(int fd, struct http *to, struct http *fm, unsigned how);
-void http_PrintfHeader(int fd, struct http *to, const char *fmt, ...);
-void http_SetHeader(int fd, struct http *to, const char *hdr);
+void http_GetReq(struct worker *w, int fd, struct http *to, struct http *fm);
+void http_CopyReq(struct worker *w, int fd, struct http *to, struct http *fm);
+void http_CopyResp(struct worker *w, int fd, struct http *to, struct http *fm);
+void http_SetResp(struct worker *w, int fd, struct http *to, const char *proto, const char *status, const char *response);
+void http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how);
+void http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, ...);
+void http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr);
int http_IsHdr(struct http_hdr *hh, char *hdr);
void http_Setup(struct http *ht, void *space, unsigned len);
int http_GetHdr(struct http *hp, const char *hdr, char **ptr);
if (sp->fd < 0) {
VSL_stats->sess_closed++;
sp->wrk->idle = sp->t_open.tv_sec;
+ sp->wrk = NULL;
vca_return_session(sp);
return (1);
}
}
VSL_stats->sess_herd++;
sp->wrk->idle = sp->t_open.tv_sec;
+ sp->wrk = NULL;
vca_return_session(sp);
return (1);
}
hp = vc->http2;
http_ClrHeader(hp);
hp->logtag = HTTP_Obj;
- http_CopyResp(sp->fd, hp, vc->http);
- http_FilterHeader(sp->fd, hp, vc->http, HTTPH_A_INS);
+ http_CopyResp(sp->wrk, sp->fd, hp, vc->http);
+ http_FilterHeader(sp->wrk, sp->fd, hp, vc->http, HTTPH_A_INS);
if (body) {
if (http_GetHdr(vc->http, H_Content_Length, &b))
cls = fetch_chunked(sp, vc->fd, vc->http);
else
cls = fetch_eof(sp, vc->fd, vc->http);
- http_PrintfHeader(sp->fd, hp,
+ http_PrintfHeader(sp->wrk, sp->fd, hp,
"Content-Length: %u", sp->obj->len);
} else
cls = 0;
if (vc == NULL)
vc = VBE_GetFd(sp->backend, sp->xid);
XXXAN(vc);
- VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
+ WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
http_ClrHeader(vc->http);
vc->http->logtag = HTTP_Tx;
- http_GetReq(vc->fd, vc->http, sp->http);
- http_FilterHeader(vc->fd, vc->http, sp->http, HTTPH_R_FETCH);
- http_PrintfHeader(vc->fd, vc->http, "X-Varnish: %u", sp->xid);
+ http_GetReq(w, vc->fd, vc->http, sp->http);
+ http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_FETCH);
+ http_PrintfHeader(w, vc->fd, vc->http, "X-Varnish: %u", sp->xid);
if (!http_GetHdr(vc->http, H_Host, &b)) {
- http_PrintfHeader(vc->fd, vc->http, "Host: %s",
+ http_PrintfHeader(w, vc->fd, vc->http, "Host: %s",
sp->backend->hostname);
}
/*--------------------------------------------------------------------*/
static void
-http_seth(int fd, struct http *to, unsigned n, enum httptag tag, const char *fm)
+http_seth(struct worker *w, int fd, struct http *to, unsigned n, enum httptag tag, const char *fm)
{
assert(n < HTTP_HDR_MAX);
to->hd[n].b = (void*)(uintptr_t)fm;
to->hd[n].e = (void*)(uintptr_t)strchr(fm, '\0');
to->hdf[n] = 0;
- VSLH(tag, fd, to, n);
+ WSLH(w, tag, fd, to, n);
}
static void
-http_copyh(int fd, struct http *to, struct http *fm, unsigned n, enum httptag tag)
+http_copyh(struct worker *w, int fd, struct http *to, struct http *fm, unsigned n, enum httptag tag)
{
assert(n < HTTP_HDR_MAX);
to->hd[n].b = fm->hd[n].b;
to->hd[n].e = fm->hd[n].e;
to->hdf[n] = fm->hdf[n];
- VSLH(tag, fd, to, n);
+ WSLH(w, tag, fd, to, n);
}
void
-http_GetReq(int fd, struct http *to, struct http *fm)
+http_GetReq(struct worker *w, int fd, struct http *to, struct http *fm)
{
CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
- http_seth(fd, to, HTTP_HDR_REQ, HTTP_T_Request, "GET");
- http_copyh(fd, to, fm, HTTP_HDR_URL, HTTP_T_URL);
- http_seth(fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, "HTTP/1.1");
+ http_seth(w, fd, to, HTTP_HDR_REQ, HTTP_T_Request, "GET");
+ http_copyh(w, fd, to, fm, HTTP_HDR_URL, HTTP_T_URL);
+ http_seth(w, fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, "HTTP/1.1");
}
void
-http_CopyReq(int fd, struct http *to, struct http *fm)
+http_CopyReq(struct worker *w, int fd, struct http *to, struct http *fm)
{
CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
- http_copyh(fd, to, fm, HTTP_HDR_REQ, HTTP_T_Request);
- http_copyh(fd, to, fm, HTTP_HDR_URL, HTTP_T_URL);
- http_copyh(fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol);
+ http_copyh(w, fd, to, fm, HTTP_HDR_REQ, HTTP_T_Request);
+ http_copyh(w, fd, to, fm, HTTP_HDR_URL, HTTP_T_URL);
+ http_copyh(w, fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol);
}
void
-http_CopyResp(int fd, struct http *to, struct http *fm)
+http_CopyResp(struct worker *w, int fd, struct http *to, struct http *fm)
{
CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
- http_copyh(fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol);
- http_copyh(fd, to, fm, HTTP_HDR_STATUS, HTTP_T_Status);
- http_copyh(fd, to, fm, HTTP_HDR_RESPONSE, HTTP_T_Response);
+ http_copyh(w, fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol);
+ http_copyh(w, fd, to, fm, HTTP_HDR_STATUS, HTTP_T_Status);
+ http_copyh(w, fd, to, fm, HTTP_HDR_RESPONSE, HTTP_T_Response);
}
void
-http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response)
+http_SetResp(struct worker *w, int fd, struct http *to, const char *proto, const char *status, const char *response)
{
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
- http_seth(fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, proto);
- http_seth(fd, to, HTTP_HDR_STATUS, HTTP_T_Status, status);
- http_seth(fd, to, HTTP_HDR_RESPONSE, HTTP_T_Response, response);
+ http_seth(w, fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, proto);
+ http_seth(w, fd, to, HTTP_HDR_STATUS, HTTP_T_Status, status);
+ http_seth(w, fd, to, HTTP_HDR_RESPONSE, HTTP_T_Response, response);
}
static void
-http_copyheader(int fd, struct http *to, struct http *fm, unsigned n)
+http_copyheader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned n)
{
CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
if (to->nhd < HTTP_HDR_MAX) {
to->hd[to->nhd].b = fm->hd[n].b;
to->hd[to->nhd].e = fm->hd[n].e;
- VSLH(HTTP_T_Header, fd, to, to->nhd);
+ WSLH(w, HTTP_T_Header, fd, to, to->nhd);
to->nhd++;
} else {
VSL_stats->losthdr++;
- VSLH(HTTP_T_LostHeader, fd, fm, n);
+ WSLH(w, HTTP_T_LostHeader, fd, fm, n);
}
}
/*--------------------------------------------------------------------*/
void
-http_FilterHeader(int fd, struct http *to, struct http *fm, unsigned how)
+http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how)
{
unsigned u;
continue;
#include "http_headers.h"
#undef HTTPH
- http_copyheader(fd, to, fm, u);
+ http_copyheader(w, fd, to, fm, u);
}
}
/*--------------------------------------------------------------------*/
void
-http_SetHeader(int fd, struct http *to, const char *hdr)
+http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr)
{
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
if (to->nhd >= HTTP_HDR_MAX) {
VSL_stats->losthdr++;
- VSL(T(to, HTTP_T_LostHeader), fd, "%s", hdr);
+ WSL(w, T(to, HTTP_T_LostHeader), fd, "%s", hdr);
return;
}
- http_seth(fd, to, to->nhd++, HTTP_T_Header, hdr);
+ http_seth(w, fd, to, to->nhd++, HTTP_T_Header, hdr);
}
/*--------------------------------------------------------------------*/
void
-http_PrintfHeader(int fd, struct http *to, const char *fmt, ...)
+http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, ...)
{
va_list ap;
unsigned l, n;
n = vsnprintf(to->f, l, fmt, ap);
if (n + 1 > l || to->nhd >= HTTP_HDR_MAX) {
VSL_stats->losthdr++;
- VSL(T(to, HTTP_T_LostHeader), fd, "%s", to->f);
+ WSL(w, T(to, HTTP_T_LostHeader), fd, "%s", to->f);
} else {
assert(to->f < to->e);
to->hd[to->nhd].b = to->f;
to->hd[to->nhd].e = to->f + n;
to->f += n + 1;
- VSLH(HTTP_T_Header, fd, to, to->nhd);
+ WSLH(w, HTTP_T_Header, fd, to, to->nhd);
to->nhd++;
}
va_end(ap);
clock_gettime(CLOCK_REALTIME, &sp->t_resp);
http_ClrHeader(sp->http);
- 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);
+ http_CopyResp(sp->wrk, sp->fd, sp->http, vc->http);
+ http_FilterHeader(sp->wrk, sp->fd, sp->http, vc->http, HTTPH_A_PASS);
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid);
/* XXX */
if (http_HdrIs(vc->http, H_Transfer_Encoding, "chunked"))
- http_PrintfHeader(sp->fd, sp->http, "Transfer-Encoding: chunked");
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Transfer-Encoding: chunked");
WRK_Reset(sp->wrk, &sp->fd);
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
}
WSL(w, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
- http_CopyReq(vc->fd, vc->http, sp->http);
- http_FilterHeader(vc->fd, vc->http, sp->http, HTTPH_R_PASS);
- http_PrintfHeader(vc->fd, vc->http, "X-Varnish: %u", sp->xid);
+ http_CopyReq(w, vc->fd, vc->http, sp->http);
+ http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_PASS);
+ http_PrintfHeader(w, vc->fd, vc->http, "X-Varnish: %u", sp->xid);
WRK_Reset(w, &vc->fd);
http_Write(w, vc->http, 0);
i = WRK_Flush(w);
VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
vc->http->logtag = HTTP_Tx;
- http_CopyReq(vc->fd, vc->http, sp->http);
- http_FilterHeader(vc->fd, vc->http, sp->http, HTTPH_R_PIPE);
- http_PrintfHeader(vc->fd, vc->http, "X-Varnish: %u", sp->xid);
+ http_CopyReq(w, vc->fd, vc->http, sp->http);
+ http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_PIPE);
+ http_PrintfHeader(w, vc->fd, vc->http, "X-Varnish: %u", sp->xid);
WRK_Reset(w, &vc->fd);
http_Write(w, vc->http, 0);
WRK_Reset(sp->wrk, &sp->fd);
sp->wrk->acct.hdrbytes += WRK_Write(sp->wrk, vsb_data(sb), vsb_len(sb));
WRK_Flush(sp->wrk);
- VSL(SLT_TxStatus, sp->id, "%d", code);
- VSL(SLT_TxProtocol, sp->id, "HTTP/1.1");
- VSL(SLT_TxResponse, sp->id, msg);
+ WSL(sp->wrk, SLT_TxStatus, sp->id, "%d", code);
+ WSL(sp->wrk, SLT_TxProtocol, sp->id, "HTTP/1.1");
+ WSL(sp->wrk, SLT_TxResponse, sp->id, msg);
vca_close_session(sp, expl);
vsb_delete(sb);
}
{
char lm[64];
- VSL(SLT_Length, sp->fd, "%u", 0);
+ WSL(sp->wrk, SLT_Length, sp->fd, "%u", 0);
http_ClrHeader(sp->http);
sp->http->logtag = HTTP_Tx;
- http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
+ http_SetResp(sp->wrk, sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
TIM_format(sp->t_req.tv_sec, lm);
- http_PrintfHeader(sp->fd, sp->http, "Date: %s", lm);
- http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
- http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm);
+ http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid);
TIM_format(sp->obj->last_modified, lm);
- http_PrintfHeader(sp->fd, sp->http, "Last-Modified: %s", lm);
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Last-Modified: %s", lm);
if (sp->doclose != NULL)
- http_SetHeader(sp->fd, sp->http, "Connection: close");
+ http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close");
WRK_Reset(sp->wrk, &sp->fd);
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
if (WRK_Flush(sp->wrk))
if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
return;
- VSL(SLT_Length, sp->fd, "%u", sp->obj->len);
+ WSL(sp->wrk, SLT_Length, sp->fd, "%u", sp->obj->len);
http_ClrHeader(sp->http);
sp->http->logtag = HTTP_Tx;
- http_CopyResp(sp->fd, sp->http, &sp->obj->http);
- http_FilterHeader(sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER);
+ http_CopyResp(sp->wrk, sp->fd, sp->http, &sp->obj->http);
+ http_FilterHeader(sp->wrk, sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER);
if (sp->xid != sp->obj->xid)
- http_PrintfHeader(sp->fd, sp->http,
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http,
"X-Varnish: %u %u", sp->xid, sp->obj->xid);
else
- http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
- http_PrintfHeader(sp->fd, sp->http, "Age: %u",
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid);
+ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u",
sp->obj->age + sp->t_req.tv_sec - sp->obj->entered);
- http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
+ http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
if (sp->doclose != NULL)
- http_SetHeader(sp->fd, sp->http, "Connection: close");
+ http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close");
WRK_Reset(sp->wrk, &sp->fd);
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
ses_sum_acct(&sp->srcaddr->acct, a);
b = sp->srcaddr->acct;
UNLOCK(&sp->srcaddr->sah->mtx);
- VSL(SLT_StatAddr, 0, "%s 0 %d %ju %ju %ju %ju %ju %ju %ju",
+ WSL(sp->wrk, SLT_StatAddr, 0,
+ "%s 0 %d %ju %ju %ju %ju %ju %ju %ju",
sp->srcaddr->addr, sp->t_end.tv_sec - b.first,
b.sess, b.req, b.pipe, b.pass,
b.fetch, b.hdrbytes, b.bodybytes);
{ \
\
sp->handling = 0; \
- VSL(SLT_VCL_call, sp->fd, "%s", #func); \
+ WSL(sp->wrk, SLT_VCL_call, sp->fd, "%s", #func); \
sp->vcl->func##_func(sp); \
- VSL(SLT_VCL_return, sp->fd, "%s", \
+ WSL(sp->wrk, SLT_VCL_return, sp->fd, "%s", \
vcl_handlingname(sp->handling)); \
assert(sp->handling & bitmap); \
assert(!(sp->handling & ~bitmap)); \
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- VSL(SLT_Debug, 0, "VCL_error(%u, %s)", code, expl);
+ WSL(sp->wrk, SLT_Debug, 0, "VCL_error(%u, %s)", code, expl);
sp->err_code = code;
sp->err_expl = expl;
}
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (params->vcl_trace)
- VSL(SLT_VCL_trace, sp->fd, "%u %d.%d", u,
+ WSL(sp->wrk, SLT_VCL_trace, sp->fd, "%u %d.%d", u,
sp->vcl->ref[u].line, sp->vcl->ref[u].pos);
}
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
- VSL(SLT_TTL, sp->fd, "%u VCL %.0f %u",
+ WSL(sp->wrk, SLT_TTL, sp->fd, "%u VCL %.0f %u",
sp->obj->xid, a, sp->t_req.tv_sec);
if (a < 0)
a = 0;
/* Only hold the lock while we find our space */
LOCKSHM(&vsl_mtx);
+ VSL_stats->shm_writes++;
+ VSL_stats->shm_records++;
assert(loghead->ptr < loghead->size);
/* Wrap if necessary */
}
LOCKSHM(&vsl_mtx);
+ VSL_stats->shm_writes++;
+ VSL_stats->shm_records++;
assert(loghead->ptr < loghead->size);
/* Wrap if we cannot fit a full size record */
return;
l = w->wlp - w->wlog;
LOCKSHM(&vsl_mtx);
+ VSL_stats->shm_writes++;
+ VSL_stats->shm_records += w->wlr;
if (loghead->ptr + l + 1 >= loghead->size)
vsl_wrap();
p = logstart + loghead->ptr;
p[0] = w->wlog[0];
UNLOCKSHM(&vsl_mtx);
w->wlp = w->wlog;
+ w->wlr = 0;
}
/*--------------------------------------------------------------------*/
memcpy(p + 4, b, l);
p[4 + l] = '\0';
p[0] = tag;
+ w->wlr++;
}
/*--------------------------------------------------------------------*/
w->wlp += 5 + n;
assert(w->wlp < w->wle);
+ w->wlr++;
va_end(ap);
}
MAC_STAT(sess_readahead, uint64_t, "u", "Session Read Ahead")
MAC_STAT(sess_herd, uint64_t, "u", "Session herd")
+MAC_STAT(shm_records, uint64_t, "u", "SHM records")
+MAC_STAT(shm_writes, uint64_t, "u", "SHM writes")
MAC_STAT(shm_cont, uint64_t, "u", "SHM MTX contention")