From phk at varnish-cache.org Mon Jul 2 08:22:30 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 02 Jul 2012 10:22:30 +0200 Subject: [master] 27d63c2 Eliminate the "init_done" and listen socket fields from struct sess by moving the VSL'ing of socket endpoints earlier in the processing. Message-ID: commit 27d63c26da9b445bf6994228668fbe9fdb6bcd2b Author: Poul-Henning Kamp Date: Mon Jul 2 08:21:23 2012 +0000 Eliminate the "init_done" and listen socket fields from struct sess by moving the VSL'ing of socket endpoints earlier in the processing. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 1d991f1..d19dc32 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -670,8 +670,6 @@ struct sess { socklen_t mysockaddrlen; struct sockaddr_storage sockaddr; struct sockaddr_storage mysockaddr; - struct listen_sock *mylsock; - int init_done; /* formatted ascii client address */ char addr[ADDR_BUFSIZE]; @@ -695,7 +693,7 @@ struct sess { void VCA_Init(void); void VCA_Shutdown(void); int VCA_Accept(struct listen_sock *ls, struct wrk_accept *wa); -void VCA_SetupSess(struct worker *w, struct sess *sp); +const char *VCA_SetupSess(struct worker *w, struct sess *sp); void VCA_FailSess(struct worker *w); /* cache_backend.c */ diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 3ca79c1..5e71d00 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -239,10 +239,11 @@ VCA_FailSess(struct worker *wrk) * We have allocated a session, move our info into it. */ -void +const char * VCA_SetupSess(struct worker *wrk, struct sess *sp) { struct wrk_accept *wa; + const char *retval; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -252,9 +253,7 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp) sp->fd = wa->acceptsock; sp->vsl_id = wa->acceptsock | VSL_CLIENTMARKER ; wa->acceptsock = -1; - sp->t_open = VTIM_real(); - sp->mylsock = wa->acceptlsock; - CHECK_OBJ_NOTNULL(sp->mylsock, LISTEN_SOCK_MAGIC); + retval = wa->acceptlsock->name; assert(wa->acceptaddrlen <= sp->sockaddrlen); memcpy(&sp->sockaddr, &wa->acceptaddr, wa->acceptaddrlen); sp->sockaddrlen = wa->acceptaddrlen; @@ -277,6 +276,7 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp) VTCP_Assert(setsockopt(sp->fd, SOL_SOCKET, SO_RCVTIMEO, &tv_rcvtimeo, sizeof tv_rcvtimeo)); #endif + return (retval); } /*--------------------------------------------------------------------*/ diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 004f815..84fc3ea 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -73,8 +73,6 @@ DOT acceptor -> first [style=bold,color=green] #include "cache.h" -#include "common/heritage.h" - #include "hash/hash_slinger.h" #include "vcl.h" #include "vcli_priv.h" @@ -112,8 +110,6 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) struct pollfd pfd[1]; double now, when; const char *why = NULL; - char laddr[ADDR_BUFSIZE]; - char lport[PORT_BUFSIZE]; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); @@ -121,30 +117,6 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) assert(req->sp == sp); - if (!sp->init_done) { - VTCP_name(&sp->sockaddr, sp->sockaddrlen, - sp->addr, sizeof sp->addr, sp->port, sizeof sp->port); - if (cache_param->log_local_addr) { - AZ(getsockname(sp->fd, (void*)&sp->mysockaddr, - &sp->mysockaddrlen)); - VTCP_name(&sp->mysockaddr, sp->mysockaddrlen, - laddr, sizeof laddr, lport, sizeof lport); - /* XXX: have no req yet */ - VSLb(req->vsl, SLT_SessionOpen, "%s %s %s %s", - sp->addr, sp->port, laddr, lport); - } else { - /* XXX: have no req yet */ - VSLb(req->vsl, SLT_SessionOpen, "%s %s %s", - sp->addr, sp->port, sp->mylsock->name); - } - - wrk->acct_tmp.sess++; - - sp->t_rx = sp->t_open; - sp->t_idle = sp->t_open; - sp->init_done = 1; - } - assert(!isnan(sp->t_rx)); AZ(req->vcl); diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 25dc687..3ed251d 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -42,6 +42,7 @@ #include "cache.h" #include "waiter/waiter.h" +#include "vtcp.h" #include "vtim.h" static unsigned ses_size = sizeof (struct sess); @@ -148,7 +149,40 @@ ses_pool_task(struct worker *wrk, void *arg) } /*-------------------------------------------------------------------- + */ +static void +ses_vsl_socket(struct req *req, const char *lsockname) +{ + char laddr[ADDR_BUFSIZE]; + char lport[PORT_BUFSIZE]; + struct sess *sp; + + CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + AN(lsockname); + sp = req->sp; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + + VTCP_name(&sp->sockaddr, sp->sockaddrlen, + sp->addr, sizeof sp->addr, sp->port, sizeof sp->port); + if (cache_param->log_local_addr) { + AZ(getsockname(sp->fd, (void*)&sp->mysockaddr, + &sp->mysockaddrlen)); + VTCP_name(&sp->mysockaddr, sp->mysockaddrlen, + laddr, sizeof laddr, lport, sizeof lport); + /* XXX: have no req yet */ + VSLb(req->vsl, SLT_SessionOpen, "%s %s %s %s %s", + sp->addr, sp->port, lsockname, laddr, lport); + } else { + /* XXX: have no req yet */ + VSLb(req->vsl, SLT_SessionOpen, "%s %s %s - -", + sp->addr, sp->port, lsockname); + } +} + +/*-------------------------------------------------------------------- * The pool-task for a newly accepted session + * + * Called from assigned worker thread */ void @@ -157,6 +191,7 @@ SES_pool_accept_task(struct worker *wrk, void *arg) struct sesspool *pp; struct req *req; struct sess *sp; + const char *lsockname; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(pp, arg, SESSPOOL_MAGIC); @@ -168,10 +203,21 @@ SES_pool_accept_task(struct worker *wrk, void *arg) VCA_FailSess(wrk); return; } - VCA_SetupSess(wrk, sp); - sp->sess_step = S_STP_NEWREQ; + + sp->t_open = VTIM_real(); + sp->t_rx = sp->t_open; + sp->t_idle = sp->t_open; + + lsockname = VCA_SetupSess(wrk, sp); + req = ses_GetReq(sp); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + + ses_vsl_socket(req, lsockname); + + wrk->acct_tmp.sess++; + + sp->sess_step = S_STP_NEWREQ; ses_pool_task(wrk, req); } From phk at varnish-cache.org Mon Jul 2 10:38:04 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 02 Jul 2012 12:38:04 +0200 Subject: [master] 4c4d6f6 Make sure that all sessions, requests and busyobj's have a unique transaction id 'vxid' Message-ID: commit 4c4d6f652d0b96aba584575e692a913172146168 Author: Poul-Henning Kamp Date: Mon Jul 2 10:37:36 2012 +0000 Make sure that all sessions, requests and busyobj's have a unique transaction id 'vxid' diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index d19dc32..ae42dd0 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -259,7 +259,7 @@ struct vsl_log { /*--------------------------------------------------------------------*/ -struct vxid { +struct vxid_pool { uint32_t next; uint32_t count; }; @@ -275,7 +275,6 @@ struct wrk_accept { socklen_t acceptaddrlen; int acceptsock; struct listen_sock *acceptlsock; - uint32_t vxid; }; /* Worker pool stuff -------------------------------------------------*/ @@ -319,6 +318,7 @@ struct worker { struct ws aws[1]; + struct vxid_pool vxid_pool; /* Temporary accounting */ struct acct acct_tmp; @@ -472,6 +472,7 @@ struct busyobj { * is recycled. */ unsigned refcount; + uint32_t vxid; uint8_t *vary; unsigned is_gzip; @@ -560,6 +561,7 @@ struct req { unsigned magic; #define REQ_MAGIC 0x2751aaa1 + uint32_t vxid; unsigned xid; int restarts; int esi_level; @@ -655,7 +657,6 @@ struct sess { int fd; unsigned vsl_id; uint32_t vxid; - uint32_t vseq; /* Cross references ------------------------------------------*/ @@ -857,7 +858,7 @@ int HTC_Complete(struct http_conn *htc); #undef HTTPH /* cache_main.c */ -uint32_t VXID_Get(struct vxid *v); +uint32_t VXID_Get(struct vxid_pool *v); extern volatile struct params * cache_param; void THR_SetName(const char *name); const char* THR_GetName(void); diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 5e71d00..bbec54f 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -248,8 +248,6 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp) CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CAST_OBJ_NOTNULL(wa, (void*)wrk->aws->f, WRK_ACCEPT_MAGIC); - sp->vxid = wa->vxid; - sp->vseq = 0; sp->fd = wa->acceptsock; sp->vsl_id = wa->acceptsock | VSL_CLIENTMARKER ; wa->acceptsock = -1; diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c index 48efe08..8f0cc50 100644 --- a/bin/varnishd/cache/cache_busyobj.c +++ b/bin/varnishd/cache/cache_busyobj.c @@ -108,6 +108,7 @@ VBO_GetBusyObj(struct worker *wrk) AZ(bo->refcount); bo->refcount = 1; + bo->vxid = VXID_Get(&wrk->vxid_pool); p = (void*)(bo + 1); p = (void*)PRNDUP(p); diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 84fc3ea..c50d503 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -277,6 +277,7 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) WS_Reset(req->ws, NULL); WS_Reset(wrk->aws, NULL); + req->vxid = VXID_Get(&wrk->vxid_pool); i = HTC_Reinit(req->htc); if (i == 1) { diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index dcb3cb1..94f2c8f 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -85,13 +85,15 @@ THR_GetName(void) } /*-------------------------------------------------------------------- + * VXID's are unique transaction numbers allocated with a minimum of + * locking overhead via pools in the worker threads. */ static uint32_t vxid_base; static struct lock vxid_lock; static void -vxid_More(struct vxid *v) +vxid_More(struct vxid_pool *v) { Lck_Lock(&vxid_lock); @@ -102,7 +104,7 @@ vxid_More(struct vxid *v) } uint32_t -VXID_Get(struct vxid *v) +VXID_Get(struct vxid_pool *v) { if (v->count == 0) vxid_More(v); diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index fa1f401..21a8a31 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -62,8 +62,6 @@ struct pool { pthread_cond_t herder_cond; pthread_t herder_thr; - struct vxid vxid; - struct lock mtx; struct taskhead idle_queue; struct taskhead front_queue; @@ -148,7 +146,6 @@ pool_accept(struct worker *wrk, void *arg) } Lck_Lock(&pp->mtx); - wa->vxid = VXID_Get(&pp->vxid); wrk2 = pool_getidleworker(pp); if (wrk2 == NULL) { /* No idle threads, do it ourselves */ diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 3ed251d..64ee6f5 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -207,12 +207,15 @@ SES_pool_accept_task(struct worker *wrk, void *arg) sp->t_open = VTIM_real(); sp->t_rx = sp->t_open; sp->t_idle = sp->t_open; + sp->vxid = VXID_Get(&wrk->vxid_pool); lsockname = VCA_SetupSess(wrk, sp); req = ses_GetReq(sp); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + req->vxid = VXID_Get(&wrk->vxid_pool); + ses_vsl_socket(req, lsockname); wrk->acct_tmp.sess++; @@ -262,12 +265,16 @@ SES_Handle(struct sess *sp, double now) struct req *req; struct sesspool *pp; + /* NB: This only works with single-threaded waiters */ + static struct vxid_pool vxid_pool; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); req = ses_GetReq(sp); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + req->vxid = VXID_Get(&vxid_pool); sp->task.func = ses_pool_task; sp->task.priv = req; sp->sess_step = S_STP_NEWREQ; From phk at varnish-cache.org Mon Jul 2 13:32:01 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 02 Jul 2012 15:32:01 +0200 Subject: [master] ef1b8cb Don't hand out zero VXIDs we need that as a magic value. Message-ID: commit ef1b8cb1b27d1e2092c147a966fc15f0e203dd68 Author: Poul-Henning Kamp Date: Mon Jul 2 13:31:42 2012 +0000 Don't hand out zero VXIDs we need that as a magic value. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index ae42dd0..2162413 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -937,7 +937,7 @@ void *VSM_Alloc(unsigned size, const char *class, const char *type, void VSL_Setup(struct vsl_log *vsl, void *ptr, size_t len); void VSM_Free(void *ptr); #ifdef VSL_ENDMARKER -void VSL(enum VSL_tag_e tag, int id, const char *fmt, ...) +void VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...) __printflike(3, 4); void VSLb(struct vsl_log *, enum VSL_tag_e tag, const char *fmt, ...) __printflike(3, 4); diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index 94f2c8f..c48a3d9 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -87,30 +87,29 @@ THR_GetName(void) /*-------------------------------------------------------------------- * VXID's are unique transaction numbers allocated with a minimum of * locking overhead via pools in the worker threads. + * + * VXID's are mostly for use in VSL and for that reason we never return + * zero vxid, in order to reserve that for "unassociated" VSL records. */ static uint32_t vxid_base; static struct lock vxid_lock; -static void -vxid_More(struct vxid_pool *v) -{ - - Lck_Lock(&vxid_lock); - v->next = vxid_base; - v->count = 32768; - vxid_base = v->count; - Lck_Unlock(&vxid_lock); -} - uint32_t VXID_Get(struct vxid_pool *v) { - if (v->count == 0) - vxid_More(v); - AN(v->count); - v->count--; - return (v->next++); + do { + if (v->count == 0) { + Lck_Lock(&vxid_lock); + v->next = vxid_base; + v->count = 32768; + vxid_base = v->count; + Lck_Unlock(&vxid_lock); + } + v->count--; + v->next++; + } while (v->next == 0); + return (v->next); } /*-------------------------------------------------------------------- diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index 85a603f..fb63e75 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -61,12 +61,12 @@ vsl_w0(uint32_t type, uint32_t length) /*--------------------------------------------------------------------*/ static inline void -vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, unsigned id) +vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, uint32_t vxid) { assert(((uintptr_t)p & 0x3) == 0); - p[1] = id; + p[1] = vxid; VMB(); p[0] = vsl_w0(tag, len); } @@ -133,7 +133,7 @@ vsl_get(unsigned len, unsigned records, unsigned flushes) */ static void -vslr(enum VSL_tag_e tag, int id, const char *b, unsigned len) +vslr(enum VSL_tag_e tag, uint32_t vxid, const char *b, unsigned len) { uint32_t *p; unsigned mlen; @@ -147,13 +147,13 @@ vslr(enum VSL_tag_e tag, int id, const char *b, unsigned len) p = vsl_get(len, 1, 0); memcpy(p + 2, b, len); - vsl_hdr(tag, p, len, id); + vsl_hdr(tag, p, len, vxid); } /*--------------------------------------------------------------------*/ void -VSL(enum VSL_tag_e tag, int id, const char *fmt, ...) +VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...) { va_list ap; unsigned n, mlen = cache_param->shm_reclen; @@ -167,12 +167,12 @@ VSL(enum VSL_tag_e tag, int id, const char *fmt, ...) va_start(ap, fmt); if (strchr(fmt, '%') == NULL) { - vslr(tag, id, fmt, strlen(fmt)); + vslr(tag, vxid, fmt, strlen(fmt)); } else { n = vsnprintf(buf, mlen, fmt, ap); if (n > mlen) n = mlen; - vslr(tag, id, buf, n); + vslr(tag, vxid, buf, n); } va_end(ap); } From phk at varnish-cache.org Mon Jul 2 20:50:26 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 02 Jul 2012 22:50:26 +0200 Subject: [master] f41fbd1 Rename '-x dumprst' to '-x dumprstparam', we may have more RST coming in the future. Message-ID: commit f41fbd19bdb300f4ec571b09e88202e6a81b72cd Author: Poul-Henning Kamp Date: Mon Jul 2 20:49:56 2012 +0000 Rename '-x dumprst' to '-x dumprstparam', we may have more RST coming in the future. diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 65dbc02..512c6dc 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -70,7 +70,7 @@ const void *pick(const struct choice *cp, const char *which, const char *kind); void MCF_ParamInit(struct cli *); void MCF_ParamSet(struct cli *, const char *param, const char *val); void MCF_ParamProtect(struct cli *, const char *arg); -void MCF_DumpRst(void); +void MCF_DumpRstParam(void); extern struct params mgt_param; /* mgt_sandbox.c */ diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 88f8253..18f1bb3 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -458,8 +458,8 @@ main(int argc, char * const *argv) VCS_Message("varnishd"); exit(0); case 'x': - if (!strcmp(optarg, "dumprst")) { - MCF_DumpRst(); + if (!strcmp(optarg, "dumprstparam")) { + MCF_DumpRstParam(); exit (0); } usage(); diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 859ef14..d17f9e2 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -1503,14 +1503,14 @@ MCF_ParamInit(struct cli *cli) /*--------------------------------------------------------------------*/ void -MCF_DumpRst(void) +MCF_DumpRstParam(void) { const struct parspec *pp; const char *p, *q; int i; printf("\n.. The following is the autogenerated " - "output from varnishd -x dumprst\n\n"); + "output from varnishd -x dumprstparam\n\n"); for (i = 0; i < nparspec; i++) { pp = parspecs[i]; printf("%s\n", pp->name); diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index f89231f..e488b3f 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -1,4 +1,4 @@ varnishtest "Code coverage of VCL compiler and RSTdump" shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" -shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprst > /dev/null 2>&1" +shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprstparam > /dev/null 2>&1" From phk at varnish-cache.org Mon Jul 2 21:08:40 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 02 Jul 2012 23:08:40 +0200 Subject: [master] 24d426d Add code to dump VSL descriptions in RST format Message-ID: commit 24d426d569038afc81d0652fcb10ad4014f8ec2b Author: Poul-Henning Kamp Date: Mon Jul 2 21:08:15 2012 +0000 Add code to dump VSL descriptions in RST format diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 18f1bb3..fd7c97f 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -70,6 +70,40 @@ struct vev_base *mgt_evb; int exit_status = 0; struct vsb *vident; +/*--------------------------------------------------------------------*/ + +static void +mgt_sltm(const char *tag, const char *sdesc, const char *ldesc) +{ + int i; + + printf("\n%s\n", tag); + i = strlen(tag); + printf("%*.*s\n\n", i, i, "------------------------------------"); + if (*ldesc != '\0') + printf("%s\n", ldesc); + else if (*sdesc != '\0') + printf("%s\n", sdesc); + else + printf("%s\n", "(description not yet written)"); + +} + +static void +mgt_DumpRstVsl(void) +{ + + printf( + "\n.. The following is autogenerated output from " + "varnishd -x dumprstvsl\n\n"); + +#define SLTM(tag, sdesc, ldesc) mgt_sltm(#tag, sdesc, ldesc); +#include "tbl/vsl_tags.h" +#undef SLTM +} + +/*--------------------------------------------------------------------*/ + static void build_vident(void) { @@ -462,6 +496,10 @@ main(int argc, char * const *argv) MCF_DumpRstParam(); exit (0); } + if (!strcmp(optarg, "dumprstvsl")) { + mgt_DumpRstVsl(); + exit (0); + } usage(); break; case 'w': diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index e488b3f..7a2cee2 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -2,3 +2,4 @@ varnishtest "Code coverage of VCL compiler and RSTdump" shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprstparam > /dev/null 2>&1" +shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprstvsl > /dev/null 2>&1" From phk at varnish-cache.org Mon Jul 2 21:21:03 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 02 Jul 2012 23:21:03 +0200 Subject: [master] 7aa0548 Turn some descriptions into intended RST format. Message-ID: commit 7aa0548615bd2f49c0e7816e127aea0b4bc36414 Author: Poul-Henning Kamp Date: Mon Jul 2 21:19:13 2012 +0000 Turn some descriptions into intended RST format. diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index fce1429..5a6c862 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -38,32 +38,55 @@ * Arguments: * Tag-Name * Short Description (1 line, max ?? chars) - * Long Description (Multi line) + * Long Description (in RST "definition list" format) */ -SLTM(Debug, "", "") -SLTM(Error, "", "") -SLTM(CLI, "CLI communication", "CLI communication between master and child process.") +SLTM(Debug, "Debug messages", + "Debug messages can normally be ignored, but are sometimes\n" + "helpful during trouble-shooting. Most debug messages must\n" + "be explicitly enabled with parameters." +) +SLTM(Error, "Error messages", + "Error messages are stuff you probably want to know." +) +SLTM(CLI, "CLI communication", + "CLI communication between master and child process." +) SLTM(StatSess, "Session statistics", "") -SLTM(ReqEnd, "Client request end", "Client request end. The first number is the XID. \n" -"The second is the time when processing of the request started.\n" -"The third is the time the request completed.\n" -"The forth is is the time elapsed between the request actually being accepted and\n" -"the start of the request processing.\n" -"The fifth number is the time elapsed from the start of the request processing \n" -"until we start delivering the object to the client.\n" -"The sixth and last number is the time from we start delivering the object\n" -"until the request completes. ") -SLTM(SessionOpen, "Client connection opened", "") -SLTM(SessionClose, "Client connection closed", "SessionClose tells you why HTTP\n" -"client-connections are closed. These can be:\n" -"timeout - No keep-alive was received within sess_timeout\n" -"Connection: close - The client specifed that keepalive should be disabled by sending a 'Connection: close' header.\n" -"no request - No initial request was received within sess_timeout.\n" -"EOF - ???\n" -"remote closed - ???\n" -"error - Processing reached vcl_error even if the status code indicates success\n" -"blast - ???") + +SLTM(ReqEnd, "Client request end", + "Marks the end of client request.\n\n" + "xid\n Transaction id.\n\n" + "Trxd\n Timestamp when the request started.\n\n" + "Tidle\n Timestamp when the request ended.\n\n" + "dTrx\n Time to receive request\n\n" + "dTproc\n Time to process request\n\n" + "dTtx\n Time to transmit response\n\n" +) + +SLTM(SessionOpen, "Client connection opened", + "The first record for a client connection, with the\n" + "socket-endpoints of the connection.\n\n" + "caddr\n Client IPv4/6 address\n\n" + "cport\n Client TCP port\n\n" + "lsock\n Listen socket name\n\n" + "laddr\n Local IPv4/6 address ('-' if $log_local_addr not set)\n\n" + "lport\n Local TCP port ('-' if $log_local_addr not set)\n\n" +) + +SLTM(SessionClose, "Client connection closed", + "SessionClose tells you why HTTP client-connections are closed. " + "These can be: " + "'timeout' - No keep-alive was received within sess_timeout. " + "'Connection: close' - The client specifed that keepalive should " + "be disabled by sending a 'Connection: close' header. " + "'no request' - No initial request was received within sess_timeout. " + "'EOF' - ??? " + "'remote closed' - ??? " + "'error' - Processing reached vcl_error even if the status code " + "indicates success. " + "' blast' - ???" +) SLTM(BackendOpen, "Backend connection opened", "") SLTM(BackendXID, "The unique ID of the backend transaction", "") SLTM(BackendReuse, "Backend connection reused", "") From phk at varnish-cache.org Tue Jul 3 07:54:48 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 03 Jul 2012 09:54:48 +0200 Subject: [master] e027388 Remove XXX comment overtaken by implementation. Message-ID: commit e02738851aeaebc4688f53b100087c8a30419098 Author: Poul-Henning Kamp Date: Mon Jul 2 21:22:16 2012 +0000 Remove XXX comment overtaken by implementation. diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index fb63e75..f5cc879 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -159,10 +159,6 @@ VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...) unsigned n, mlen = cache_param->shm_reclen; char buf[mlen]; - /* - * XXX: consider formatting into a stack buffer then move into - * XXX: shmlog with vslr(). - */ AN(fmt); va_start(ap, fmt); From phk at varnish-cache.org Tue Jul 3 07:54:48 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 03 Jul 2012 09:54:48 +0200 Subject: [master] 72d3574 Log SessionOpen with VSL() so we can be sure it is always the first VSL record for a session. Message-ID: commit 72d35747a9ed1f2d5a5d146df4b5eceedb201981 Author: Poul-Henning Kamp Date: Tue Jul 3 07:53:42 2012 +0000 Log SessionOpen with VSL() so we can be sure it is always the first VSL record for a session. Make $log_local_address default to on. diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 64ee6f5..7f88212 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -149,18 +149,20 @@ ses_pool_task(struct worker *wrk, void *arg) } /*-------------------------------------------------------------------- + * VSL log the endpoints of the TCP connection. + * + * We use VSL() to get the sessions vxid and to make sure tha this + * VSL comes before anything else for this session. */ + static void -ses_vsl_socket(struct req *req, const char *lsockname) +ses_vsl_socket(struct sess *sp, const char *lsockname) { char laddr[ADDR_BUFSIZE]; char lport[PORT_BUFSIZE]; - struct sess *sp; - CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - AN(lsockname); - sp = req->sp; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + AN(lsockname); VTCP_name(&sp->sockaddr, sp->sockaddrlen, sp->addr, sizeof sp->addr, sp->port, sizeof sp->port); @@ -169,14 +171,12 @@ ses_vsl_socket(struct req *req, const char *lsockname) &sp->mysockaddrlen)); VTCP_name(&sp->mysockaddr, sp->mysockaddrlen, laddr, sizeof laddr, lport, sizeof lport); - /* XXX: have no req yet */ - VSLb(req->vsl, SLT_SessionOpen, "%s %s %s %s %s", - sp->addr, sp->port, lsockname, laddr, lport); } else { - /* XXX: have no req yet */ - VSLb(req->vsl, SLT_SessionOpen, "%s %s %s - -", - sp->addr, sp->port, lsockname); + strcpy(laddr, "-"); + strcpy(lport, "-"); } + VSL(SLT_SessionOpen, sp->vxid, "%s %s %s %s %s", + sp->addr, sp->port, lsockname, laddr, lport); } /*-------------------------------------------------------------------- @@ -210,13 +210,13 @@ SES_pool_accept_task(struct worker *wrk, void *arg) sp->vxid = VXID_Get(&wrk->vxid_pool); lsockname = VCA_SetupSess(wrk, sp); + ses_vsl_socket(sp, lsockname); req = ses_GetReq(sp); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); req->vxid = VXID_Get(&wrk->vxid_pool); - ses_vsl_socket(req, lsockname); wrk->acct_tmp.sess++; diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index d17f9e2..b030caa 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -1047,9 +1047,11 @@ static const struct parspec input_parspec[] = { "on", "bool" }, { "log_local_address", tweak_bool, &mgt_param.log_local_addr, 0, 0, "Log the local address on the TCP connection in the " - "SessionOpen shared memory record.\n", + "SessionOpen VSL record.\n" + "Disabling this saves a getsockname(2) system call " + "per TCP connection.\n", 0, - "off", "bool" }, + "on", "bool" }, { "waiter", tweak_waiter, NULL, 0, 0, "Select the waiter kernel interface.\n", WIZARD | MUST_RESTART, diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index 598eae9..e0c5afa 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -8,6 +8,7 @@ server s1 { # This requires non-local binds to be disabled. If you see this fail # and are on Linux, ensure /proc/net/ipv4/ip_nonlocal_bind is set to 0. varnish v1 -cliok "param.set listen_address ${bad_ip}:0" +varnish v1 -cliok "param.set log_local_address off" varnish v1 -vcl+backend {} -clierr 300 start varnish v1 -cliok "param.set listen_address 127.0.0.1:0,${bad_ip}:9082" diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 5a6c862..c79f378 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -37,7 +37,7 @@ * * Arguments: * Tag-Name - * Short Description (1 line, max ?? chars) + * Short Description (1 line, max ? chars) * Long Description (in RST "definition list" format) */ @@ -69,9 +69,9 @@ SLTM(SessionOpen, "Client connection opened", "socket-endpoints of the connection.\n\n" "caddr\n Client IPv4/6 address\n\n" "cport\n Client TCP port\n\n" - "lsock\n Listen socket name\n\n" - "laddr\n Local IPv4/6 address ('-' if $log_local_addr not set)\n\n" - "lport\n Local TCP port ('-' if $log_local_addr not set)\n\n" + "lsock\n Listen socket\n\n" + "laddr\n Local IPv4/6 address ('-' if !$log_local_addr)\n\n" + "lport\n Local TCP port ('-' if !$log_local_addr)\n\n" ) SLTM(SessionClose, "Client connection closed", @@ -81,11 +81,11 @@ SLTM(SessionClose, "Client connection closed", "'Connection: close' - The client specifed that keepalive should " "be disabled by sending a 'Connection: close' header. " "'no request' - No initial request was received within sess_timeout. " - "'EOF' - ??? " - "'remote closed' - ??? " + "'EOF' - ? " + "'remote closed' - ? " "'error' - Processing reached vcl_error even if the status code " "indicates success. " - "' blast' - ???" + "' blast' - ?" ) SLTM(BackendOpen, "Backend connection opened", "") SLTM(BackendXID, "The unique ID of the backend transaction", "") From phk at varnish-cache.org Tue Jul 3 10:07:21 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 03 Jul 2012 12:07:21 +0200 Subject: [master] 0008c89 Sanitize and document the Sess{Open|Close} VSL messages. Message-ID: commit 0008c89ed6dd5c6010a43cfb4b6762d0d9bbebf4 Author: Poul-Henning Kamp Date: Tue Jul 3 10:06:24 2012 +0000 Sanitize and document the Sess{Open|Close} VSL messages. Some breakage on the far side of varnishapi expected, mode to come. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 2162413..1a42bd0 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -75,6 +75,30 @@ body_status(enum body_status e) } } +/*--------------------------------------------------------------------*/ + +enum sess_close { + SC_NULL = 0, +#define SESS_CLOSE(nm, desc) SC_##nm, +#include "tbl/sess_close.h" +#undef SESS_CLOSE +}; + +static inline const char * +sess_close_str(enum sess_close sc, int want_desc) +{ + switch (sc) { + case SC_NULL: return(want_desc ? "(null)": "NULL"); +#define SESS_CLOSE(nm, desc) case SC_##nm: return(want_desc ? desc : #nm); +#include "tbl/sess_close.h" +#undef SESS_CLOSE + + default: return(want_desc ? "(invalid)" : "INVALID"); + } +} + +/*--------------------------------------------------------------------*/ + /* * NB: HDR_STATUS is only used in cache_http.c, everybody else uses the * http->status integer field. @@ -585,7 +609,7 @@ struct req { unsigned char digest[DIGEST_LEN]; - const char *doclose; + enum sess_close doclose; struct exp exp; unsigned cur_method; unsigned handling; @@ -655,6 +679,7 @@ struct sess { enum sess_step sess_step; int fd; + enum sess_close reason; unsigned vsl_id; uint32_t vxid; @@ -840,7 +865,7 @@ const char *http_GetReq(const struct http *hp); int http_HdrIs(const struct http *hp, const char *hdr, const char *val); uint16_t http_DissectRequest(struct req *); uint16_t http_DissectResponse(struct http *sp, const struct http_conn *htc); -const char *http_DoConnection(const struct http *hp); +enum sess_close http_DoConnection(const struct http *); void http_CopyHome(const struct http *hp); void http_Unset(struct http *hp, const char *hdr); void http_CollectHdr(struct http *hp, const char *hdr); @@ -919,8 +944,8 @@ unsigned WRW_Write(const struct worker *w, const void *ptr, int len); unsigned WRW_WriteH(const struct worker *w, const txt *hh, const char *suf); /* cache_session.c [SES] */ -void SES_Close(struct sess *sp, const char *reason); -void SES_Delete(struct sess *sp, const char *reason, double now); +void SES_Close(struct sess *sp, enum sess_close reason); +void SES_Delete(struct sess *sp, enum sess_close reason, double now); void SES_Charge(struct worker *, struct req *); struct sesspool *SES_NewPool(struct pool *pp, unsigned pool_no); void SES_DeletePool(struct sesspool *sp); diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index c50d503..e71ad87 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -109,7 +109,7 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) int i, j, tmo; struct pollfd pfd[1]; double now, when; - const char *why = NULL; + enum sess_close why = SC_NULL; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); @@ -143,16 +143,16 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) req->t_req = now; return (0); } else if (i == -1) { - why = "EOF"; + why = SC_REM_CLOSE; break; } else if (i == -2) { - why = "overflow"; + why = SC_RX_OVERFLOW; break; } else if (i == -3) { /* Nothing but whitespace */ when = sp->t_idle + cache_param->timeout_idle; if (when < now) { - why = "timeout"; + why = SC_RX_TIMEOUT; break; } when = sp->t_idle + cache_param->timeout_linger; @@ -170,7 +170,7 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) when = sp->t_rx + cache_param->timeout_req; tmo = (int)(1e3 * (when - now)); if (when < now || tmo == 0) { - why = "req timeout"; + why = SC_RX_TIMEOUT; break; } } @@ -255,7 +255,7 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) req->hash_always_miss = 0; req->hash_ignore_busy = 0; - if (sp->fd >= 0 && req->doclose != NULL) { + if (sp->fd >= 0 && req->doclose != SC_NULL) { /* * This is an orderly close of the connection; ditch nolinger * before we close, to get queued data transmitted. @@ -268,7 +268,7 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) wrk->stats.sess_closed++; AZ(req->vcl); SES_ReleaseReq(req); - SES_Delete(sp, NULL, NAN); + SES_Delete(sp, SC_NULL, NAN); return (SESS_DONE_RET_GONE); } @@ -318,9 +318,9 @@ CNT_Session(struct worker *wrk, struct req *req) */ if (sp->sess_step == S_STP_NEWREQ && VTCP_blocking(sp->fd)) { if (errno == ECONNRESET) - SES_Close(sp, "remote closed"); + SES_Close(sp, SC_REM_CLOSE); else - SES_Close(sp, "error"); + SES_Close(sp, SC_TX_ERROR); sdr = cnt_sess_done(sp, wrk, req); assert(sdr == SESS_DONE_RET_GONE); return; @@ -437,7 +437,7 @@ cnt_prepresp(struct worker *wrk, struct req *req) req->res_mode |= RES_CHUNKED; } else { req->res_mode |= RES_EOF; - req->doclose = "EOF mode"; + req->doclose = SC_TX_EOF; } } @@ -573,7 +573,7 @@ cnt_error(struct worker *wrk, struct req *req) (uint16_t)cache_param->http_max_hdr); bo->stats = NULL; if (req->obj == NULL) { - req->doclose = "Out of objects"; + req->doclose = SC_OVERLOAD; req->director = NULL; http_Teardown(bo->beresp); http_Teardown(bo->bereq); @@ -611,7 +611,7 @@ cnt_error(struct worker *wrk, struct req *req) /* We always close when we take this path */ - req->doclose = "error"; + req->doclose = SC_TX_ERROR; req->wantbody = 1; assert(req->handling == VCL_RET_DELIVER); @@ -1504,7 +1504,7 @@ cnt_start(struct worker *wrk, struct req *req) /* If we could not even parse the request, just close */ if (req->err_code == 400) { - SES_Close(req->sp, "junk"); + SES_Close(req->sp, SC_RX_JUNK); return (1); } @@ -1520,7 +1520,7 @@ cnt_start(struct worker *wrk, struct req *req) if (strcasecmp(p, "100-continue")) { req->err_code = 417; } else if (strlen(r) != write(req->sp->fd, r, strlen(r))) { - SES_Close(req->sp, "remote closed"); + SES_Close(req->sp, SC_REM_CLOSE); return (1); } } diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index 7e4305e..cc722ce 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -325,7 +325,7 @@ ESI_Deliver(struct req *req) st->ptr + off, l2); if (WRW_Error(req->wrk)) { SES_Close(req->sp, - "remote closed"); + SC_REM_CLOSE); p = e; break; } @@ -376,7 +376,7 @@ ESI_Deliver(struct req *req) if (vgz != NULL) VGZ_WrwFlush(req->wrk, vgz); if (WRW_Flush(req->wrk)) { - SES_Close(req->sp, "remote closed"); + SES_Close(req->sp, SC_REM_CLOSE); p = e; break; } diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c index 411b2d3..eb5998a 100644 --- a/bin/varnishd/cache/cache_http.c +++ b/bin/varnishd/cache/cache_http.c @@ -410,19 +410,19 @@ http_GetHdrField(const struct http *hp, const char *hdr, * XXX: redo with http_GetHdrField() ? */ -const char * +enum sess_close http_DoConnection(const struct http *hp) { char *p, *q; - const char *ret; + enum sess_close ret; unsigned u; if (!http_GetHdr(hp, H_Connection, &p)) { if (hp->protover < 11) - return ("not HTTP/1.1"); - return (NULL); + return (SC_REQ_HTTP10); + return (SC_NULL); } - ret = NULL; + ret = SC_NULL; AN(p); for (; *p; p++) { if (vct_issp(*p)) @@ -434,7 +434,7 @@ http_DoConnection(const struct http *hp) break; u = pdiff(p, q); if (u == 5 && !strncasecmp(p, "close", u)) - ret = "Connection: close"; + ret = SC_REQ_CLOSE; u = http_findhdr(hp, u, p); if (u != 0) hp->hdf[u] |= HDF_FILTER; diff --git a/bin/varnishd/cache/cache_pipe.c b/bin/varnishd/cache/cache_pipe.c index 8fa9e3c..238d0a3 100644 --- a/bin/varnishd/cache/cache_pipe.c +++ b/bin/varnishd/cache/cache_pipe.c @@ -92,7 +92,7 @@ PipeRequest(struct req *req) i = WRW_FlushRelease(wrk); if (i) { - SES_Close(req->sp, "pipe"); + SES_Close(req->sp, SC_TX_PIPE); VDI_CloseFd(&vc); return; } @@ -132,7 +132,7 @@ PipeRequest(struct req *req) fds[1].fd = -1; } } - SES_Close(req->sp, "pipe"); + SES_Close(req->sp, SC_TX_PIPE); VDI_CloseFd(&vc); bo->vbc = NULL; } diff --git a/bin/varnishd/cache/cache_response.c b/bin/varnishd/cache/cache_response.c index cdad653..e82ab67 100644 --- a/bin/varnishd/cache/cache_response.c +++ b/bin/varnishd/cache/cache_response.c @@ -285,5 +285,5 @@ RES_WriteObj(struct req *req) WRW_EndChunk(req->wrk); if (WRW_FlushRelease(req->wrk) && req->sp->fd >= 0) - SES_Close(req->sp, "remote closed"); + SES_Close(req->sp, SC_REM_CLOSE); } diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 7f88212..59dccf6 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -175,7 +175,7 @@ ses_vsl_socket(struct sess *sp, const char *lsockname) strcpy(laddr, "-"); strcpy(lport, "-"); } - VSL(SLT_SessionOpen, sp->vxid, "%s %s %s %s %s", + VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s", sp->addr, sp->port, lsockname, laddr, lport); } @@ -203,6 +203,7 @@ SES_pool_accept_task(struct worker *wrk, void *arg) VCA_FailSess(wrk); return; } + wrk->acct_tmp.sess++; sp->t_open = VTIM_real(); sp->t_rx = sp->t_open; @@ -217,9 +218,6 @@ SES_pool_accept_task(struct worker *wrk, void *arg) req->vxid = VXID_Get(&wrk->vxid_pool); - - wrk->acct_tmp.sess++; - sp->sess_step = S_STP_NEWREQ; ses_pool_task(wrk, req); } @@ -249,7 +247,7 @@ SES_ScheduleReq(struct req *req) sp->t_idle = VTIM_real(); AN (req->vcl); VCL_Rel(&req->vcl); - SES_Delete(sp, "dropped", sp->t_idle); + SES_Delete(sp, SC_OVERLOAD, sp->t_idle); return (1); } return (0); @@ -282,7 +280,7 @@ SES_Handle(struct sess *sp, double now) if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) { VSC_C_main->client_drop_late++; sp->t_idle = VTIM_real(); - SES_Delete(sp, "dropped", sp->t_idle); + SES_Delete(sp, SC_OVERLOAD, sp->t_idle); } } @@ -293,12 +291,12 @@ SES_Handle(struct sess *sp, double now) */ void -SES_Close(struct sess *sp, const char *reason) +SES_Close(struct sess *sp, enum sess_close reason) { int i; assert(sp->fd >= 0); - VSL(SLT_SessionClose, sp->vsl_id, "%s", reason); + sp->reason = reason; i = close(sp->fd); assert(i == 0 || errno != EBADF); /* XXX EINVAL seen */ sp->fd = -1; @@ -314,7 +312,7 @@ SES_Close(struct sess *sp, const char *reason) */ void -SES_Delete(struct sess *sp, const char *reason, double now) +SES_Delete(struct sess *sp, enum sess_close reason, double now) { struct acct *b; struct sesspool *pp; @@ -324,7 +322,7 @@ SES_Delete(struct sess *sp, const char *reason, double now) CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - if (reason != NULL) + if (reason != SC_NULL) SES_Close(sp, reason); if (isnan(now)) now = VTIM_real(); @@ -338,10 +336,11 @@ SES_Delete(struct sess *sp, const char *reason, double now) b = &sp->acct_ses; - VSL(SLT_StatSess, sp->vsl_id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju", - sp->addr, sp->port, + VSL(SLT_SessClose, sp->vxid, + "%s %.3f %ju %ju %ju %ju %ju %ju", + sess_close_str(sp->reason, 0), now - sp->t_open, - b->sess, b->req, b->pipe, b->pass, + b->req, b->pipe, b->pass, b->fetch, b->hdrbytes, b->bodybytes); MPL_Free(pp->mpl_sess, sp); diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt index 5ddd6ce..2a15a34 100644 --- a/bin/varnishd/flint.lnt +++ b/bin/varnishd/flint.lnt @@ -109,6 +109,10 @@ -esym(458, name_key) ////////////// +// 436 = Apparent preprocessor directive in invocation of macro '___' +-emacro(436, SLTM) + +////////////// +libh mgt_event.h diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index fd7c97f..7b42437 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -86,7 +86,7 @@ mgt_sltm(const char *tag, const char *sdesc, const char *ldesc) printf("%s\n", sdesc); else printf("%s\n", "(description not yet written)"); - + } static void diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c index e89d550..53d7f0f 100644 --- a/bin/varnishd/waiter/cache_waiter.c +++ b/bin/varnishd/waiter/cache_waiter.c @@ -74,6 +74,6 @@ WAIT_Enter(struct sess *sp) * acceptor thread, to reduce syscall density of the latter. */ if (VTCP_nonblocking(sp->fd)) - SES_Close(sp, "remote closed"); + SES_Close(sp, SC_REM_CLOSE); waiter->pass(waiter_priv, sp); } diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c index 423bf26..a7403d6 100644 --- a/bin/varnishd/waiter/cache_waiter_kqueue.c +++ b/bin/varnishd/waiter/cache_waiter_kqueue.c @@ -133,7 +133,7 @@ vwk_sess_ev(struct vwk *vwk, const struct kevent *kp, double now) return; } else if (kp->flags & EV_EOF) { VTAILQ_REMOVE(&vwk->sesshead, sp, list); - SES_Delete(sp, "EOF", now); + SES_Delete(sp, SC_REM_CLOSE, now); return; } else { VSL(SLT_Debug, sp->vsl_id, @@ -204,7 +204,7 @@ vwk_thread(void *priv) break; VTAILQ_REMOVE(&vwk->sesshead, sp, list); // XXX: not yet (void)VTCP_linger(sp->fd, 0); - SES_Delete(sp, "timeout", now); + SES_Delete(sp, SC_RX_TIMEOUT, now); } } } diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c index a31bec1..4339617 100644 --- a/bin/varnishd/waiter/cache_waiter_poll.c +++ b/bin/varnishd/waiter/cache_waiter_poll.c @@ -162,7 +162,7 @@ vwp_main(void *priv) VTAILQ_REMOVE(&vwp->sesshead, sp, list); vwp_unpoll(vwp, fd); // XXX: not yet (void)VTCP_linger(sp->fd, 0); - SES_Delete(sp, "timeout", now); + SES_Delete(sp, SC_RX_TIMEOUT, now); } } if (v2 && vwp->pollfd[vwp->pipes[0]].revents) { diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c index a606861..bf7d32b 100644 --- a/bin/varnishlog/varnishlog.c +++ b/bin/varnishlog/varnishlog.c @@ -115,9 +115,9 @@ h_order(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len, ob[fd] = VSB_new_auto(); assert(ob[fd] != NULL); } - if ((tag == SLT_BackendOpen || tag == SLT_SessionOpen || + if ((tag == SLT_BackendOpen || tag == SLT_SessOpen || (tag == SLT_ReqStart && - last[fd] != SLT_SessionOpen && + last[fd] != SLT_SessOpen && last[fd] != SLT_VCL_acl) || (tag == SLT_BackendXID && last[fd] != SLT_BackendOpen)) && @@ -127,7 +127,7 @@ h_order(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len, * the end of the previous one. Spit it out anyway before * starting on the new one. */ - if (last[fd] != SLT_SessionClose) + if (last[fd] != SLT_SessClose) VSB_printf(ob[fd], "%5d %-12s %c %s\n", fd, "Interrupted", type, VSL_tags[tag]); h_order_finish(fd, vd); @@ -165,7 +165,6 @@ h_order(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len, case SLT_ReqEnd: case SLT_BackendClose: case SLT_BackendReuse: - case SLT_StatSess: h_order_finish(fd, vd); break; default: @@ -180,8 +179,8 @@ do_order(struct VSM_data *vd) int i; if (!b_flag) { - VSL_Select(vd, SLT_SessionOpen); - VSL_Select(vd, SLT_SessionClose); + VSL_Select(vd, SLT_SessOpen); + VSL_Select(vd, SLT_SessClose); VSL_Select(vd, SLT_ReqEnd); } if (!c_flag) { diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c index 9bdf87f..9c9267e 100644 --- a/bin/varnishncsa/varnishncsa.c +++ b/bin/varnishncsa/varnishncsa.c @@ -535,11 +535,11 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, lp->df_b = trimline(ptr, end); break; - case SLT_SessionClose: + case SLT_SessClose: if (!lp->active) break; - if (strncmp(ptr, "pipe", len) == 0 || - strncmp(ptr, "error", len) == 0) { + if (strncmp(ptr, "TX_PIPE", len) == 0 || + strncmp(ptr, "TX_ERROR", len) == 0) { clean_logline(lp); break; } diff --git a/include/tbl/sess_close.h b/include/tbl/sess_close.h new file mode 100644 index 0000000..c9d28ba --- /dev/null +++ b/include/tbl/sess_close.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2012 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/*lint -save -e525 -e539 */ + +SESS_CLOSE(REM_CLOSE, "Client Closed") +SESS_CLOSE(REQ_CLOSE, "Client requested close") +SESS_CLOSE(REQ_HTTP10, "proto < HTTP.1.1") +SESS_CLOSE(RX_JUNK, "Received junk data") +SESS_CLOSE(RX_OVERFLOW, "Received buffer overflow") +SESS_CLOSE(RX_TIMEOUT, "Receive timeout") +SESS_CLOSE(TX_PIPE, "Piped transaction") +SESS_CLOSE(TX_ERROR, "Error transaction") +SESS_CLOSE(TX_EOF, "EOF transmission") +SESS_CLOSE(OVERLOAD, "Out of some resource") + +/*lint -restore */ diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index c79f378..27fed4d 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -52,7 +52,6 @@ SLTM(Error, "Error messages", SLTM(CLI, "CLI communication", "CLI communication between master and child process." ) -SLTM(StatSess, "Session statistics", "") SLTM(ReqEnd, "Client request end", "Marks the end of client request.\n\n" @@ -64,7 +63,9 @@ SLTM(ReqEnd, "Client request end", "dTtx\n Time to transmit response\n\n" ) -SLTM(SessionOpen, "Client connection opened", +/*---------------------------------------------------------------------*/ + +SLTM(SessOpen, "Client connection opened", "The first record for a client connection, with the\n" "socket-endpoints of the connection.\n\n" "caddr\n Client IPv4/6 address\n\n" @@ -74,19 +75,24 @@ SLTM(SessionOpen, "Client connection opened", "lport\n Local TCP port ('-' if !$log_local_addr)\n\n" ) -SLTM(SessionClose, "Client connection closed", - "SessionClose tells you why HTTP client-connections are closed. " - "These can be: " - "'timeout' - No keep-alive was received within sess_timeout. " - "'Connection: close' - The client specifed that keepalive should " - "be disabled by sending a 'Connection: close' header. " - "'no request' - No initial request was received within sess_timeout. " - "'EOF' - ? " - "'remote closed' - ? " - "'error' - Processing reached vcl_error even if the status code " - "indicates success. " - "' blast' - ?" +#define SESS_CLOSE(nm, desc) " " #nm "\n\t" desc "\n\n" + +SLTM(SessClose, "Client connection closed", + "SessionClose is the last record for any client connection.\n\n" + "reason\n Why the connection closed.\n\n" +#include + "duration\n How long the session were open.\n\n" + "Nreq\n How many requests on session.\n\n" + "Npipe\n If 'pipe' were used on session.\n\n" + "Npass\n Requests handled with pass.\n\n" + "Nfetch\n Backend fetches by session.\n\n" + "Bhdr\n Header bytes sent on session.\n\n" + "Bbody\n Body bytes sent on session.\n\n" ) +#undef SESS_CLOSE + +/*---------------------------------------------------------------------*/ + SLTM(BackendOpen, "Backend connection opened", "") SLTM(BackendXID, "The unique ID of the backend transaction", "") SLTM(BackendReuse, "Backend connection reused", "") From phk at varnish-cache.org Tue Jul 3 12:33:53 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 03 Jul 2012 14:33:53 +0200 Subject: [master] 74e2d3f Seems I have either hit a GCC bug or a lack of imagination in the C-standardisation. (Even money if you ask me...) Message-ID: commit 74e2d3f3dc50967a64fe818f7fcb78af06f76e1a Author: Poul-Henning Kamp Date: Tue Jul 3 12:33:09 2012 +0000 Seems I have either hit a GCC bug or a lack of imagination in the C-standardisation. (Even money if you ask me...) GCC users will just have to live with marginally works docs. diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 27fed4d..37c2e6b 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -80,7 +80,13 @@ SLTM(SessOpen, "Client connection opened", SLTM(SessClose, "Client connection closed", "SessionClose is the last record for any client connection.\n\n" "reason\n Why the connection closed.\n\n" +#ifdef __clang__ +/* + * GCC barfs at this construct, but we have no way to ask compiler + * if it is _not_ a GCC compiler since CLANG also defines __GNUC__ + */ #include +#endif "duration\n How long the session were open.\n\n" "Nreq\n How many requests on session.\n\n" "Npipe\n If 'pipe' were used on session.\n\n" From phk at varnish-cache.org Tue Jul 3 12:46:37 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 03 Jul 2012 14:46:37 +0200 Subject: [master] 88c7737 Also update waiter_epoll to new SES_* api. Message-ID: commit 88c77374bab8f4c63235005200a452ae29b669b0 Author: Poul-Henning Kamp Date: Tue Jul 3 14:46:06 2012 +0200 Also update waiter_epoll to new SES_* api. diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c index 6ad5be5..a15bbe5 100644 --- a/bin/varnishd/waiter/cache_waiter_epoll.c +++ b/bin/varnishd/waiter/cache_waiter_epoll.c @@ -133,13 +133,13 @@ vwe_eev(struct vwe *vwe, const struct epoll_event *ep, double now) SES_Handle(sp, now); } else if (ep->events & EPOLLERR) { VTAILQ_REMOVE(&vwe->sesshead, sp, list); - SES_Delete(sp, "ERR", now); + SES_Delete(sp, SC_REM_CLOSE, now); } else if (ep->events & EPOLLHUP) { VTAILQ_REMOVE(&vwe->sesshead, sp, list); - SES_Delete(sp, "HUP", now); + SES_Delete(sp, SC_REM_CLOSE, now); } else if (ep->events & EPOLLRDHUP) { VTAILQ_REMOVE(&vwe->sesshead, sp, list); - SES_Delete(sp, "RHUP", now); + SES_Delete(sp, SC_REM_CLOSE, now); } } } @@ -192,7 +192,7 @@ vwe_thread(void *priv) break; VTAILQ_REMOVE(&vwe->sesshead, sp, list); // XXX: not yet VTCP_linger(sp->fd, 0); - SES_Delete(sp, "timeout", now); + SES_Delete(sp, SC_RX_TIMEOUT, now); } } return (NULL); From martin at varnish-cache.org Tue Jul 3 13:03:36 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Tue, 03 Jul 2012 15:03:36 +0200 Subject: [master] 673c50d Fix parsing of -T and -S arguments from shared memory in varnishadm when using the -n option. Message-ID: commit 673c50deaa447eb80c7830f2adef0749347f44bc Author: Martin Blix Grydeland Date: Tue Jul 3 13:30:40 2012 +0200 Fix parsing of -T and -S arguments from shared memory in varnishadm when using the -n option. Code had reversed the no -T argument error check, and also required the optional -S argument to be present. Fixes: #1160 diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index f4c262c..3dc7c79 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -298,20 +298,19 @@ n_arg_sock(const char *n_arg) fprintf(stderr, "%s\n", VSM_Error(vsd)); return (-1); } - if (T_arg == NULL) { - if (VSM_Get(vsd, &vt, "Arg", "-T", "")) { - fprintf(stderr, "No -T arg in shared memory\n"); - return (-1); - } - T_start = T_arg = strdup(vt.b); + + if (!VSM_Get(vsd, &vt, "Arg", "-T", "")) { + fprintf(stderr, "No -T arg in shared memory\n"); + return (-1); } - if (S_arg == NULL) { - if (VSM_Get(vsd, &vt, "Arg", "-S", "")) { - fprintf(stderr, "No -S arg in shared memory\n"); - return (-1); - } + AN(vt.b); + T_start = T_arg = strdup(vt.b); + + if (VSM_Get(vsd, &vt, "Arg", "-S", "")) { + AN(vt.b); S_arg = strdup(vt.b); } + sock = -1; while (*T_arg) { p = strchr(T_arg, '\n'); From martin at varnish-cache.org Tue Jul 3 13:03:36 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Tue, 03 Jul 2012 15:03:36 +0200 Subject: [master] ad65eb5 Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache Message-ID: commit ad65eb54a7b57d116e7517385b0c4ab2f2fb6217 Merge: 673c50d 0008c89 Author: Martin Blix Grydeland Date: Tue Jul 3 14:11:51 2012 +0200 Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache From martin at varnish-cache.org Tue Jul 3 13:03:36 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Tue, 03 Jul 2012 15:03:36 +0200 Subject: [master] 47dd5d2 Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache Message-ID: commit 47dd5d223032610b0dc01d54277eb18d8bb75c5d Merge: ad65eb5 74e2d3f Author: Martin Blix Grydeland Date: Tue Jul 3 14:36:02 2012 +0200 Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache From martin at varnish-cache.org Tue Jul 3 13:03:36 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Tue, 03 Jul 2012 15:03:36 +0200 Subject: [master] aa9e09c Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache Message-ID: commit aa9e09c8df6e32742fec5eaa700ae4626dc1cb35 Merge: 47dd5d2 88c7737 Author: Martin Blix Grydeland Date: Tue Jul 3 15:00:42 2012 +0200 Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache From tfheen at varnish-cache.org Wed Jul 4 13:14:56 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Wed, 04 Jul 2012 15:14:56 +0200 Subject: [master] 0c82d95 Distribute sess_close.h too Message-ID: commit 0c82d957d368863d18a32175da247ff753ed33d2 Author: Tollef Fog Heen Date: Wed Jul 4 15:14:51 2012 +0200 Distribute sess_close.h too diff --git a/include/Makefile.am b/include/Makefile.am index 3faa540..b70a825 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -9,6 +9,7 @@ nobase_pkginclude_HEADERS = \ tbl/http_headers.h \ tbl/http_response.h \ tbl/locks.h \ + tbl/sess_close.h \ tbl/steps.h \ tbl/symbol_kind.h \ tbl/vcc_types.h \ From daghf at varnish-cache.org Thu Jul 5 12:37:16 2012 From: daghf at varnish-cache.org (Dag Haavi Finstad) Date: Thu, 05 Jul 2012 14:37:16 +0200 Subject: [master] dec9455 Fix for an issue where varnishlog reports an incorrect "Length" entry on gunzipped delivery Message-ID: commit dec9455a9f0bb1b1e3c5b65d3d626d531db25fbb Author: Dag Haavi Finstad Date: Mon Jul 2 09:50:30 2012 +0200 Fix for an issue where varnishlog reports an incorrect "Length" entry on gunzipped delivery diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 1a42bd0..6c46831 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -823,7 +823,7 @@ 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, ssize_t ibufl); -void VGZ_WrwFlush(const struct worker *wrk, struct vgz *vg); +void VGZ_WrwFlush(struct worker *wrk, struct vgz *vg); /* Return values */ #define VGZ_ERROR -1 diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index 9078834..1ebabb0 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -355,13 +355,15 @@ VGZ_WrwGunzip(struct worker *wrk, struct vgz *vg, const void *ibuf, /*--------------------------------------------------------------------*/ void -VGZ_WrwFlush(const struct worker *wrk, struct vgz *vg) +VGZ_WrwFlush(struct worker *wrk, struct vgz *vg) { 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; (void)WRW_Write(wrk, vg->m_buf, vg->m_len); (void)WRW_Flush(wrk); vg->m_len = 0; From apj at varnish-cache.org Fri Jul 6 13:27:00 2012 From: apj at varnish-cache.org (Andreas Plesner Jacobsen) Date: Fri, 06 Jul 2012 15:27:00 +0200 Subject: [master] e855267 Make sure the user understands that this is about the default configuration Message-ID: commit e855267d8c4029a0056434eaf373b1fe9e9ffb96 Author: Andreas Plesner Jacobsen Date: Fri Jul 6 15:25:48 2012 +0200 Make sure the user understands that this is about the default configuration diff --git a/doc/sphinx/tutorial/cookies.rst b/doc/sphinx/tutorial/cookies.rst index deda74c..c75171f 100644 --- a/doc/sphinx/tutorial/cookies.rst +++ b/doc/sphinx/tutorial/cookies.rst @@ -89,7 +89,7 @@ Cookies coming from the backend ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If your backend server sets a cookie using the Set-Cookie header -Varnish will not cache the page. A hit-for-pass object (see -:ref:`tutorial-vcl_fetch_actions`) is created. So, if the backend -server acts silly and sets unwanted cookies just unset the Set-Cookie -header and all should be fine. +Varnish will not cache the page in the default configuration. A +hit-for-pass object (see :ref:`tutorial-vcl_fetch_actions`) is created. +So, if the backend server acts silly and sets unwanted cookies just unset +the Set-Cookie header and all should be fine. From martin at varnish-cache.org Thu Jul 12 07:46:24 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 12 Jul 2012 09:46:24 +0200 Subject: [3.0] 596246e Make n_sess be the difference between in use and released session objects. Message-ID: commit 596246ea3fc36847dc27d1672dd37a8fef817ac5 Author: Martin Blix Grydeland Date: Thu Jun 28 14:43:12 2012 +0200 Make n_sess be the difference between in use and released session objects. This avoids a memory race on the n_sess counter, which can lead to excessive session object allocation. Keeping the counters of in use and released separate allows the acceptor to continue to run lockless. Fixes: #897 diff --git a/bin/varnishd/cache_session.c b/bin/varnishd/cache_session.c index 1ebca44..d94ac7b 100644 --- a/bin/varnishd/cache_session.c +++ b/bin/varnishd/cache_session.c @@ -74,6 +74,8 @@ static struct lock ses_mem_mtx; /*--------------------------------------------------------------------*/ static struct lock stat_mtx; +static volatile uint64_t n_sess_grab = 0; +static uint64_t n_sess_rel = 0; /*--------------------------------------------------------------------*/ @@ -214,7 +216,8 @@ SES_New(void) CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); } - VSC_C_main->n_sess++; /* XXX: locking ? */ + /* Only updated from the cache acceptor - no lock needed */ + n_sess_grab++; return (sp); } @@ -255,7 +258,6 @@ SES_Delete(struct sess *sp) AZ(sp->obj); AZ(sp->vcl); - VSC_C_main->n_sess--; /* XXX: locking ? */ assert(!isnan(b->first)); assert(!isnan(sp->t_end)); if (sp->addr == NULL) @@ -267,10 +269,8 @@ SES_Delete(struct sess *sp) b->sess, b->req, b->pipe, b->pass, b->fetch, b->hdrbytes, b->bodybytes); if (sm->workspace != params->sess_workspace) { - Lck_Lock(&stat_mtx); - VSC_C_main->n_sess_mem--; - Lck_Unlock(&stat_mtx); free(sm); + sm = NULL; } else { /* Clean and prepare for reuse */ ses_setup(sm); @@ -279,6 +279,14 @@ SES_Delete(struct sess *sp) Lck_Unlock(&ses_mem_mtx); } + /* Update statistics */ + Lck_Lock(&stat_mtx); + if (sm == NULL) + VSC_C_main->n_sess_mem--; + n_sess_rel++; + VSC_C_main->n_sess = n_sess_grab - n_sess_rel; + Lck_Unlock(&stat_mtx); + /* Try to precreate some ses-mem so the acceptor will not have to */ if (VSC_C_main->n_sess_mem < VSC_C_main->n_sess + 10) { sm = ses_sm_alloc(); From phk at varnish-cache.org Fri Jul 13 00:03:51 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Fri, 13 Jul 2012 02:03:51 +0200 Subject: [master] c31f908 Add my official "statement of interest" in HTTP/2.0 Message-ID: commit c31f908382f51b0dba5dce10fc6127574afb40a9 Author: Poul-Henning Kamp Date: Fri Jul 13 00:03:33 2012 +0000 Add my official "statement of interest" in HTTP/2.0 diff --git a/doc/sphinx/phk/http20.rst b/doc/sphinx/phk/http20.rst new file mode 100644 index 0000000..e2a6ed0 --- /dev/null +++ b/doc/sphinx/phk/http20.rst @@ -0,0 +1,316 @@ +.. _phk_http20_lack_of_interest: + +====================================== +Why HTTP/2.0 does not seem interesting +====================================== + +This is the email I sent to the IETF HTTP Working Group:: + + + From: Poul-Henning Kamp + Subject: HTTP/2 Expression of luke-warm interest: Varnish + To: HTTP Working Group + Message-Id: <41677.1342136900 at critter.freebsd.dk> + Date: Thu, 12 Jul 2012 23:48:20 GMT + + +This is Varnish' response to the call for expression of interest +in HTTP/2[1]. + +Varnish +------- + +Presently Varnish[2] only implements a subset of HTTP/1.1 consistent +with its hybrid/dual "http-server" / "http-proxy" role. + +I cannot at this point say much about what Varnish will or will +not implement protocol wise in the future. + +Our general policy is to only add protocols if we can do a better +job than the alternative, which is why we have not implemented HTTPS +for instance. + +Should the outcome of the HTTP/2.0 effort result in a protocol which +gains traction, Varnish will probably implement it, but we are +unlikely to become an early implementation, given the current +proposals at the table. + + +Why I'm not impressed +--------------------- + +I have read all, and participated in one, of the three proposals +presently on the table. + +Overall, I find all three proposals are focused on solving yesteryears +problems, rather than on creating a protocol that stands a chance +to last us the next 20 years. + +Each proposal comes out of a particular "camp" and therefore +all seem to suffer a certain amount from tunnel-vision. + +It is my considered opinion that none of the proposals have what +it will take to replace HTTP/1.1 in practice. + + +What if they made a new protocol, and nobody used it ? +------------------------------------------------------ + +We have learned, painfully, that an IPv6 which is only marginally +better than IPv4 and which offers no tangible benefit for the people +who have the cost/trouble of the upgrade, does not penetrate the +network on its own, and barely even on goverments mandate. + +We have also learned that a protocol which delivers the goods can +replace all competition in virtually no time. + +See for instance how SSH replaced TELNET, REXEC, RSH, SUPDUP, and +to a large extent KERBEROS, in a matter of a few years. + +Or I might add, how HTTP replaced GOPHER[3]. + +HTTP/1.1 is arguably in the top-five most used protocols, after +IP, TCP, UDP and, sadly, ICMP, and therefore coming up with a +replacement should be approached humbly. + + +Beating HTTP/1.1 +---------------- + +Fortunately, there are many ways to improve over HTTP/1.1, which +lacks support for several widely used features, and sports many +trouble-causing weeds, both of which are ripe for HTTP/2.0 to pounce +on. + +Most notably HTTP/1.1 lacks a working session/endpoint-identity +facility, a shortcoming which people have pasted over with the +ill-conceived Cookie hack. + +Cookies are, as the EU commision correctly noted, fundamentally +flawed, because they store potentially sensitive information on +whatever computer the user happens to use, and as a result of various +abuses and incompetences, EU felt compelled to legislate a "notice +and announce" policy for HTTP-cookies. + +But it doesn't stop there: The information stored in cookies have +potentialiiy very high value for the HTTP server, and because the +server has no control over the integrity of the storage, we are now +seing cookies being crypto-signed, to prevent forgeries. + +The term "bass ackwards" comes to mind. + +Cookies are also one of the main wasters of bandwidth, disabling +caching by default, sending lots of cookies were they are are not +needed, which made many sites register separate domains for image +content, to "save" bandwidth by avoiding cookies. + +The term "not really helping" also comes to mind. + +In my view, HTTP/2.0 should kill Cookies as a concept, and replace +it with a session/identity facility, which makes it easier to +do things right with HTTP/2.0 than with HTTP/1.1. + +Being able to be "automatically in compliance" by using HTTP/2.0 +no matter how big dick-heads your advertisers are or how incompetent +your web-developers are, would be a big selling point for HTTP/2.0 +over HTTP/1.1. + +However, as I read them, none of the three proposals try to address, +much less remedy, this situation, nor for that matter any of the +many other issues or troubles with HTTP/1.x. + +What's even worse, they are all additive proposals, which add a +new layer of complexity without removing any of the old complexity +from the protocol. + +My conclusion is that HTTP/2.0 is really just a grandiose name for +HTTP/1.2: An attempt to smoothe out some sharp corners, to save a +bit of bandwidth, but not get anywhere near all the architectural +problems of HTTP/1.1 and to preserve faithfully its heritage of +badly thought out sedimentary hacks. + +And therefore, I don't see much chance that the current crop of +HTTP/2.0 proposals will fare significantly better than IPv6 with +respect to adoption. + + +HTTP Routers +------------ + +One particular hot-spot in the HTTP world these days is the +"load-balancer" or as I prefer to call it, the "HTTP router". + +These boxes sit at the DNS resolved IP numbers and distributes +client requests to a farm of HTTP servers, based on simple criteria +such as "Host:", URI patterns and/or server availability, sometimes +with an added twist of geo-location[4]. + +HTTP routers see very high traffic densities, the highest traffic +densities, because they are the focal point of DoS mitigation, flash +mobs and special event traffic spikes. + +In the time frame where HTTP/2.0 will become standardized, HTTP +routers will routinely deal with 40Gbit/s traffic and people will +start to arcitect for 1Tbit/s traffic. + +HTTP routers are usually only interested in a small part of the +HTTP request and barely in the response at all, usually only the +status code. + +The demands for bandwidth efficiency has made makers of these devices +take many unwarranted shortcuts, for instance assuming that requests +always start on a packet boundary, "nulling out" HTTP headers by +changing the first character and so on. + +Whatever HTTP/2.0 becomes, I strongly urge IETF and the WG to +formally recognize the role of HTTP routers, and to actively design +the protocol to make life easier for HTTP routers, so that they can +fulfill their job, while being standards compliant. + +The need for HTTP routers does not disappear just because HTTPS is +employed, and serious thought should be turned to the question of +mixing HTTP and HTTPS traffic on the same TCP connection, while +allowing a HTTP router on the server side to correctly distribute +requests to different servers. + +One simple way to gain a lot of benefit for little cost in this +area, would be to assign "flow-labels" which each are restricted +to one particular Host: header, allowing HTTP routers to only examine +the first request on each flow. + + +SPDY +---- + +SPDY has come a long way, and has served as a very worthwhile proof +of concept prototype, to document that there are gains to be had. + +But as Frederick P. Brooks admonishes us: Always throw the prototype +away and start over, because you will throw it away eventually, and +doing so early saves time and effort. + +Overall, I find the design approach taken in SPDY deeply flawed. + +For instance identifying the standardized HTTP headers, by a 4-byte +length and textual name, and then applying a deflate compressor to +save bandwidth is totally at odds with the job of HTTP routers which +need to quickly extract the Host: header in order to route the +traffic, preferably without committing extensive resources to each +request. + +It is also not at all clear if the built-in dictionary is well +researched or just happens to work well for some subset of present +day websites, and at the very least some kind of versioning of this +dictionary should be incorporated. + +It is still unclear for me if or how SPDY can be used on TCP port +80 or if it will need a WKS allocation of its own, which would open +a ton of issues with firewalling, filtering and proxying during +deployment. + +(This is one of the things which makes it hard to avoid the feeling +that SPDY really wants to do away with all the "middle-men") + +With my security-analyst hat on, I see a lot of DoS potential in +the SPDY protocol, many ways in which the client can make the server +expend resources, and foresee a lot of complexity in implementing +the server side to mitigate and deflect malicious traffic. + +Server Push breaks the HTTP transaction model, and opens a pile of +cans of security and privacy issues, which whould not be sneaked +in during the design of a transport-encoding for HTTP/1+ traffic, +but rather be standardized as an independent and well analysed +extension to HTTP in general. + + +HTTP Speed+Mobility +------------------- + +Is really just SPDY with WebSockets underneath. + +I'm really not sure I see any benefit to that, execept that the +encoding chosen is marginally more efficient to implement in +hardware than SPDY. + +I have not understood why it has "mobility" in the name, a word +which only makes an appearance in the ID as part of the name. + +If the use of the word "mobility" only refers only to bandwidth +usage, I would call its use borderline-deceptive. + +If it covers session stability across IP# changes for mobile +devices, I have missed it in my reading. + + +draft-tarreau-httpbis-network-friendly-00 +----------------------------------------- + +I have participated a little bit in this draft initially, but it +uses a number of concepts which I think are very problematic for +high performance (as in 1Tbit/s) implementations, for instance +variant-size length fields etc. + +I do think the proposal is much better than the other two, taking +a much more fundamental view of the task, and if for no other reason, +because it takes an approach to bandwidth-saving based on enumeration +and repeat markers, rather than throwing everything after deflate +and hope for a miracle. + +I think this protocol is the best basis to start from, but like +the other two, it has a long way to go, before it can truly +earn the name HTTP/2.0. + + +Conclusion +---------- + +Overall, I don't see any of the three proposals offer anything that +will make the majority of web-sites go "Ohh we've been waiting for +that!" + +Bigger sites will be entised by small bandwidth savings, but the +majority of the HTTP users will see scant or no net positive benefit +if one or more of these three proposals were to become HTTP/2.0 + +Considering how sketchy the HTTP/1.1 interop is described it is hard +to estimate how much trouble (as in: "Why doesn't this website work ?") +their deployment will cause, nor is it entirely clear to what extent +the experience with SPDY is representative of a wider deployment or +only of 'flying under the radar' with respect to people with an +interest in intercepting HTTP traffic. + +Given the role of HTTP/1.1 in the net, I fear that the current rush +to push out a HTTP/2.0 by purely additive means is badly misguided, +and approaching a critical mass which will delay or prevent adoption +on its own. + +At the end of the day, a HTTP request or a HTTP response is just +some metadata and an optional chunk of bytes as body, and if it +already takes 700 pages to standardize that, and HTTP/2.0 will add +another 100 pages to it, we're clearly doing something wrong. + +I think it would be far better to start from scratch, look at what +HTTP/2.0 should actually do, and then design a simple, efficient +and future proof protocol to do just that, and leave behind all +the aggregations of badly thought out hacks of HTTP/1.1. + +But to the extent that the WG produces a HTTP/2.0 protocol which +people will start to use, the Varnish project will be interested. + + +Poul-Henning Kamp + +Author of Varnish + + +[1] http://trac.tools.ietf.org/wg/httpbis/trac/wiki/Http2CfI + +[2] http://varnish-cache.org/ + +[3] Yes, I'm that old. + +[4] Which is really a transport level job, but it was left out of IPv6 + along with other useful features, to not delay adoption[5]. + +[5] No, I'm not kidding. + diff --git a/doc/sphinx/phk/index.rst b/doc/sphinx/phk/index.rst index 58935c7..d4a2513 100644 --- a/doc/sphinx/phk/index.rst +++ b/doc/sphinx/phk/index.rst @@ -7,7 +7,9 @@ Poul-Hennings random outbursts You may or may not want to know what Poul-Henning think. .. toctree:: + :titlesonly: + http20.rst varnish_does_not_hash.rst thetoolsweworkwith.rst three-zero.rst From phk at varnish-cache.org Fri Jul 13 00:07:28 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Fri, 13 Jul 2012 02:07:28 +0200 Subject: [master] 9f1fd24 Hmm, that hid too much, try this instead... Message-ID: commit 9f1fd247f1d12de5409e7291de326cc554d825e5 Author: Poul-Henning Kamp Date: Fri Jul 13 00:07:10 2012 +0000 Hmm, that hid too much, try this instead... diff --git a/doc/sphinx/phk/index.rst b/doc/sphinx/phk/index.rst index d4a2513..f4f880d 100644 --- a/doc/sphinx/phk/index.rst +++ b/doc/sphinx/phk/index.rst @@ -7,7 +7,7 @@ Poul-Hennings random outbursts You may or may not want to know what Poul-Henning think. .. toctree:: - :titlesonly: + :maxdepth: 1 http20.rst varnish_does_not_hash.rst From martin at varnish-cache.org Fri Jul 13 09:05:17 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Fri, 13 Jul 2012 11:05:17 +0200 Subject: [master] d105f98 Document the version requirements of the varnishreplay input file. Message-ID: commit d105f989a0586c0ffefcf46458d4891adf0bce49 Author: Martin Blix Grydeland Date: Fri Jul 13 09:56:24 2012 +0200 Document the version requirements of the varnishreplay input file. diff --git a/doc/sphinx/reference/varnishreplay.rst b/doc/sphinx/reference/varnishreplay.rst index 4be103f..da3df36 100644 --- a/doc/sphinx/reference/varnishreplay.rst +++ b/doc/sphinx/reference/varnishreplay.rst @@ -32,8 +32,9 @@ The following options are available: -D Turn on debugging mode. --r file Parse logs from this file. This option is mandatory. - +-r file Parse logs from this file. The input file has to be from + a varnishlog of the same version as the varnishreplay + binary. This option is mandatory. SEE ALSO ======== From tfheen at varnish-cache.org Fri Jul 13 09:36:07 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Fri, 13 Jul 2012 11:36:07 +0200 Subject: [3.0] b164c06 Fix for an issue where the bodybytes counter is not updated correctly on gunzipped delivery Message-ID: commit b164c06c36098b8c2881bac2d5cc2fbfca6f10f7 Author: Dag Haavi Finstad Date: Thu Jul 5 14:54:03 2012 +0200 Fix for an issue where the bodybytes counter is not updated correctly on gunzipped delivery diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c index 5a0ee9e..f22d48a 100644 --- a/bin/varnishd/cache_response.c +++ b/bin/varnishd/cache_response.c @@ -185,6 +185,7 @@ res_WriteGunzipObj(struct sess *sp) (void)i; } if (obufl) { + sp->wrk->acct_tmp.bodybytes += obufl; (void)WRW_Write(sp->wrk, obuf, obufl); (void)WRW_Flush(sp->wrk); } From lkarsten at varnish-cache.org Mon Jul 16 08:18:15 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Mon, 16 Jul 2012 10:18:15 +0200 Subject: [master] 83ab485 Front is slightly easier to understand Message-ID: commit 83ab485743c413ce50693769aaf4a7bc268b1dc4 Author: Lasse Karstensen Date: Mon Jul 16 10:17:43 2012 +0200 Front is slightly easier to understand diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 6c46831..7328779 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -171,7 +171,7 @@ struct ws { unsigned overflow; /* workspace overflowed */ const char *id; /* identity */ char *s; /* (S)tart of buffer */ - char *f; /* (F)ree pointer */ + char *f; /* (F)ree/front pointer */ char *r; /* (R)eserved length */ char *e; /* (E)nd of buffer */ }; From martin at varnish-cache.org Mon Jul 16 10:37:47 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Mon, 16 Jul 2012 12:37:47 +0200 Subject: [master] c288891 Fix the parallell make check Message-ID: commit c2888919964c0498c511db5e7158244e15771eab Author: Martin Blix Grydeland Date: Mon Jul 16 12:37:17 2012 +0200 Fix the parallell make check diff --git a/bin/varnishtest/Makefile.am b/bin/varnishtest/Makefile.am index ec68889..9287b3c 100644 --- a/bin/varnishtest/Makefile.am +++ b/bin/varnishtest/Makefile.am @@ -5,7 +5,8 @@ TEST_EXTENSIONS = .vtc TESTS = @VTC_TESTS@ # Make sure we run check-local first -check: check-local check-am +check: check-am check-local +check-am: check-local # See if list of checks have changed, recheck check-local: if [ "$$(cd $(srcdir) && echo tests/*.vtc)" != "@VTC_TESTS@" ]; then \ From daghf at varnish-cache.org Tue Jul 17 13:39:07 2012 From: daghf at varnish-cache.org (Dag Haavi Finstad) Date: Tue, 17 Jul 2012 15:39:07 +0200 Subject: [3.0] 1f4006e Merge branch '3.0' of ssh://git.varnish-cache.org/git/varnish-cache into 3.0 Message-ID: commit 1f4006e83a3b257c9a604dd40b857d6292608b46 Merge: b50bbd6 b164c06 Author: Dag Haavi Finstad Date: Mon Jul 16 12:36:15 2012 +0200 Merge branch '3.0' of ssh://git.varnish-cache.org/git/varnish-cache into 3.0 From daghf at varnish-cache.org Tue Jul 17 13:39:07 2012 From: daghf at varnish-cache.org (Dag Haavi Finstad) Date: Tue, 17 Jul 2012 15:39:07 +0200 Subject: [3.0] b50bbd6 Fix for an issue where the bodybytes counter is not updated correctly on gunzipped delivery Message-ID: commit b50bbd6f6beefab8f8dda8b82cae66cf8324e0af Author: Dag Haavi Finstad Date: Thu Jul 5 14:54:03 2012 +0200 Fix for an issue where the bodybytes counter is not updated correctly on gunzipped delivery diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c index 5a0ee9e..f22d48a 100644 --- a/bin/varnishd/cache_response.c +++ b/bin/varnishd/cache_response.c @@ -185,6 +185,7 @@ res_WriteGunzipObj(struct sess *sp) (void)i; } if (obufl) { + sp->wrk->acct_tmp.bodybytes += obufl; (void)WRW_Write(sp->wrk, obuf, obufl); (void)WRW_Flush(sp->wrk); } From phk at varnish-cache.org Tue Jul 17 20:11:01 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 17 Jul 2012 22:11:01 +0200 Subject: [master] ae3e5a3 Push allocation of request into the assigned worker thread when we come back from the waiter, to lessen amount of work waiter does. Message-ID: commit ae3e5a3a9fcf0214c0d0cfc75f7ae909cf439f8a Author: Poul-Henning Kamp Date: Tue Jul 17 20:10:09 2012 +0000 Push allocation of request into the assigned worker thread when we come back from the waiter, to lessen amount of work waiter does. diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index bbec54f..da2cdf8 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -172,6 +172,8 @@ vca_pace_good(void) /*-------------------------------------------------------------------- * Accept on a listen socket, and handle error returns. + * + * Called from a worker thread from a pool */ int diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 59dccf6..d2cca4b 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -28,9 +28,14 @@ * * Session management * - * This is a little bit of a mixed back, containing both memory management + * This is a little bit of a mixed bag, containing both memory management * and various state-change functions. * + * The overall picture is complicated by the fact that requests can + * disembark their worker-threads if they hit a busy object, then come + * back later in a different worker thread to continue. + * XXX: I wonder if that complexity pays of any more ? + * */ #include "config.h" @@ -121,11 +126,11 @@ ses_new(struct sesspool *pp) } /*-------------------------------------------------------------------- - * The pool-task function for sessions + * Process new/existing request on this session. */ static void -ses_pool_task(struct worker *wrk, void *arg) +ses_req_pool_task(struct worker *wrk, void *arg) { struct req *req; struct sess *sp; @@ -149,6 +154,28 @@ ses_pool_task(struct worker *wrk, void *arg) } /*-------------------------------------------------------------------- + * Allocate a request + vxid, call ses_req_pool_task() + */ + +static void +ses_sess_pool_task(struct worker *wrk, void *arg) +{ + struct req *req; + struct sess *sp; + + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); + CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC); + + req = ses_GetReq(sp); + CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + + req->vxid = VXID_Get(&wrk->vxid_pool); + + sp->sess_step = S_STP_NEWREQ; + ses_req_pool_task(wrk, req); +} + +/*-------------------------------------------------------------------- * VSL log the endpoints of the TCP connection. * * We use VSL() to get the sessions vxid and to make sure tha this @@ -189,7 +216,6 @@ void SES_pool_accept_task(struct worker *wrk, void *arg) { struct sesspool *pp; - struct req *req; struct sess *sp; const char *lsockname; @@ -213,17 +239,13 @@ SES_pool_accept_task(struct worker *wrk, void *arg) lsockname = VCA_SetupSess(wrk, sp); ses_vsl_socket(sp, lsockname); - req = ses_GetReq(sp); - CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - - req->vxid = VXID_Get(&wrk->vxid_pool); - - sp->sess_step = S_STP_NEWREQ; - ses_pool_task(wrk, req); + ses_sess_pool_task(wrk, sp); } /*-------------------------------------------------------------------- * Schedule a request back on a work-thread from its sessions pool + * + * This is used to reschedule requests waiting on busy objects */ int @@ -239,7 +261,7 @@ SES_ScheduleReq(struct req *req) CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - sp->task.func = ses_pool_task; + sp->task.func = ses_req_pool_task; sp->task.priv = req; if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) { @@ -260,22 +282,14 @@ SES_ScheduleReq(struct req *req) void SES_Handle(struct sess *sp, double now) { - struct req *req; struct sesspool *pp; - /* NB: This only works with single-threaded waiters */ - static struct vxid_pool vxid_pool; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - req = ses_GetReq(sp); - CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - req->vxid = VXID_Get(&vxid_pool); - sp->task.func = ses_pool_task; - sp->task.priv = req; - sp->sess_step = S_STP_NEWREQ; + sp->task.func = ses_sess_pool_task; + sp->task.priv = sp; sp->t_rx = now; if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) { VSC_C_main->client_drop_late++; From phk at varnish-cache.org Wed Jul 18 20:09:51 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 18 Jul 2012 22:09:51 +0200 Subject: [master] 3cc4a72 Introduce an enum to make the states of HTTP reception more readable. Message-ID: commit 3cc4a726bf5d4ff8044883daacffc9bd46f607ec Author: Poul-Henning Kamp Date: Wed Jul 18 20:09:21 2012 +0000 Introduce an enum to make the states of HTTP reception more readable. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 7328779..63a7c3d 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -871,12 +871,20 @@ void http_Unset(struct http *hp, const char *hdr); void http_CollectHdr(struct http *hp, const char *hdr); /* cache_httpconn.c */ +enum htc_status_e { + HTC_ALL_WHITESPACE = -3, + HTC_OVERFLOW = -2, + HTC_ERROR_EOF = -1, + HTC_NEED_MORE = 0, + HTC_COMPLETE = 1 +}; + void HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *, unsigned maxbytes, unsigned maxhdr); int HTC_Reinit(struct http_conn *htc); -int HTC_Rx(struct http_conn *htc); +enum htc_status_e HTC_Rx(struct http_conn *htc); ssize_t HTC_Read(struct http_conn *htc, void *d, size_t len); -int HTC_Complete(struct http_conn *htc); +enum htc_status_e HTC_Complete(struct http_conn *htc); #define HTTPH(a, b, c) extern char b[]; #include "tbl/http_headers.h" diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index e71ad87..d98d490 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -106,10 +106,11 @@ DOT } static int cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) { - int i, j, tmo; + int j, tmo; struct pollfd pfd[1]; double now, when; enum sess_close why = SC_NULL; + enum htc_status_e hs; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); @@ -135,20 +136,20 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) assert(j >= 0); now = VTIM_real(); if (j != 0) - i = HTC_Rx(req->htc); + hs = HTC_Rx(req->htc); else - i = HTC_Complete(req->htc); - if (i == 1) { + hs = HTC_Complete(req->htc); + if (hs == HTC_COMPLETE) { /* Got it, run with it */ req->t_req = now; return (0); - } else if (i == -1) { + } else if (hs == HTC_ERROR_EOF) { why = SC_REM_CLOSE; break; - } else if (i == -2) { + } else if (hs == HTC_OVERFLOW) { why = SC_RX_OVERFLOW; break; - } else if (i == -3) { + } else if (hs == HTC_ALL_WHITESPACE) { /* Nothing but whitespace */ when = sp->t_idle + cache_param->timeout_idle; if (when < now) { diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index ab2aabc..3b9b08d 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -437,8 +437,9 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody) struct worker *wrk; struct busyobj *bo; struct http *hp; + enum htc_status_e hs; int retry = -1; - int i; + int i, first; struct http_conn *htc; wrk = req->wrk; @@ -499,31 +500,31 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody) VTCP_set_read_timeout(vc->fd, vc->first_byte_timeout); - i = HTC_Rx(htc); - - if (i < 0) { - VSLb(req->vsl, SLT_FetchError, - "http first read error: %d %d (%s)", - i, errno, strerror(errno)); - VDI_CloseFd(&bo->vbc); - /* XXX: other cleanup ? */ - /* Retryable if we never received anything */ - return (i == -1 ? retry : -1); - } - - VTCP_set_read_timeout(vc->fd, vc->between_bytes_timeout); - - while (i == 0) { - i = HTC_Rx(htc); - if (i < 0) { + first = 1; + do { + hs = HTC_Rx(htc); + if (hs == HTC_OVERFLOW) { VSLb(req->vsl, SLT_FetchError, - "http first read error: %d %d (%s)", - i, errno, strerror(errno)); + "http %sread error: overflow", + first ? "first " : ""); VDI_CloseFd(&bo->vbc); /* XXX: other cleanup ? */ return (-1); } - } + if (hs == HTC_ERROR_EOF) { + VSLb(req->vsl, SLT_FetchError, + "http %sread error: EOF", + first ? "first " : ""); + VDI_CloseFd(&bo->vbc); + /* XXX: other cleanup ? */ + return (retry); + } + if (first) { + first = 0; + VTCP_set_read_timeout(vc->fd, + vc->between_bytes_timeout); + } + } while (hs != HTC_COMPLETE); hp = bo->beresp; diff --git a/bin/varnishd/cache/cache_httpconn.c b/bin/varnishd/cache/cache_httpconn.c index 890dfd3..211e8a9 100644 --- a/bin/varnishd/cache/cache_httpconn.c +++ b/bin/varnishd/cache/cache_httpconn.c @@ -46,44 +46,6 @@ #include "vct.h" -/*-------------------------------------------------------------------- - * Check if we have a complete HTTP request or response yet - * - * Return values: - * -3 All whitespace so far - * 0 No, keep trying - * >0 Yes, it is this many bytes long. - */ - -static int -htc_header_complete(txt *t) -{ - const char *p; - - Tcheck(*t); - assert(*t->e == '\0'); - /* Skip any leading white space */ - for (p = t->b ; vct_islws(*p); p++) - continue; - if (p == t->e) { - /* All white space */ - t->e = t->b; - *t->e = '\0'; - return (-3); - } - while (1) { - p = strchr(p, '\n'); - if (p == NULL) - return (0); - p++; - if (*p == '\r') - p++; - if (*p == '\n') - break; - } - p++; - return (p - t->b); -} /*--------------------------------------------------------------------*/ @@ -139,15 +101,45 @@ HTC_Reinit(struct http_conn *htc) * Return 1 if we have a complete HTTP procol header */ -int +/*-------------------------------------------------------------------- + * Check if we have a complete HTTP request or response yet + * + */ + +enum htc_status_e HTC_Complete(struct http_conn *htc) { int i; + const char *p; + txt *t; CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); - i = htc_header_complete(&htc->rxbuf); - if (i <= 0) - return (i); + + t = &htc->rxbuf; + Tcheck(*t); + assert(*t->e == '\0'); + + /* Skip any leading white space */ + for (p = t->b ; vct_islws(*p); p++) + continue; + if (p == t->e) { + /* All white space */ + t->e = t->b; + *t->e = '\0'; + return (HTC_ALL_WHITESPACE); + } + while (1) { + p = strchr(p, '\n'); + if (p == NULL) + return (HTC_NEED_MORE); + p++; + if (*p == '\r') + p++; + if (*p == '\n') + break; + } + p++; + i = p - t->b; WS_ReleaseP(htc->ws, htc->rxbuf.e); AZ(htc->pipeline.b); AZ(htc->pipeline.e); @@ -156,20 +148,14 @@ HTC_Complete(struct http_conn *htc) htc->pipeline.e = htc->rxbuf.e; htc->rxbuf.e = htc->pipeline.b; } - return (1); + return (HTC_COMPLETE); } /*-------------------------------------------------------------------- * Receive more HTTP protocol bytes - * Returns: - * -3 all whitespace so far - * -2 overflow - * -1 error/EOF - * 0 more needed - * 1 got complete HTTP header */ -int +enum htc_status_e HTC_Rx(struct http_conn *htc) { int i; @@ -179,7 +165,7 @@ HTC_Rx(struct http_conn *htc) i = (htc->ws->r - htc->rxbuf.e) - 1; /* space for NUL */ if (i <= 0) { WS_ReleaseP(htc->ws, htc->rxbuf.b); - return (-2); + return (HTC_OVERFLOW); } i = read(htc->fd, htc->rxbuf.e, i); if (i <= 0) { @@ -188,7 +174,7 @@ HTC_Rx(struct http_conn *htc) * so consequently an EOF can not be OK */ WS_ReleaseP(htc->ws, htc->rxbuf.b); - return (-1); + return (HTC_ERROR_EOF); } htc->rxbuf.e += i; *htc->rxbuf.e = '\0'; From phk at varnish-cache.org Wed Jul 18 21:27:05 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 18 Jul 2012 23:27:05 +0200 Subject: [master] c34f10e Move the temporary accounting structure from wrk to req and eliminate two SES_Charge() calls that have nothing to charge. Message-ID: commit c34f10e1213ae4df0db74d6f0477140cfa047aea Author: Poul-Henning Kamp 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_ 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) From phk at varnish-cache.org Thu Jul 19 08:30:12 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 19 Jul 2012 10:30:12 +0200 Subject: [master] 1172fc9 Various minor cleanups for code clarity. Message-ID: commit 1172fc93e4d5d3827fcc2dc9abceaef96b1f5cb1 Author: Poul-Henning Kamp Date: Thu Jul 19 08:29:54 2012 +0000 Various minor cleanups for code clarity. diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 1fcaff4..c200bd3 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -175,8 +175,8 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) } } } - AZ(req->vcl); SES_ReleaseReq(req); + assert(why != SC_NULL); SES_Delete(sp, why, now); return (1); } @@ -254,14 +254,8 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) req->hash_always_miss = 0; req->hash_ignore_busy = 0; - if (sp->fd >= 0 && req->doclose != SC_NULL) { - /* - * This is an orderly close of the connection; ditch nolinger - * before we close, to get queued data transmitted. - */ - // XXX: not yet (void)VTCP_linger(sp->fd, 0); + if (sp->fd >= 0 && req->doclose != SC_NULL) SES_Close(sp, req->doclose); - } if (sp->fd < 0) { wrk->stats.sess_closed++; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 5e994f7..6478a00 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -133,12 +133,9 @@ static void ses_req_pool_task(struct worker *wrk, void *arg) { struct req *req; - struct sess *sp; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC); - sp = req->sp; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); THR_SetRequest(req); AZ(wrk->aws->r); @@ -180,6 +177,9 @@ ses_sess_pool_task(struct worker *wrk, void *arg) * * We use VSL() to get the sessions vxid and to make sure tha this * VSL comes before anything else for this session. + * + * This is a separate procedure only to isolate the two stack buffers. + * */ static void @@ -317,12 +317,7 @@ SES_Close(struct sess *sp, enum sess_close reason) } /*-------------------------------------------------------------------- - * (Close &) Free or Recycle a session. - * - * If the workspace has changed, deleted it, otherwise wash it, and put - * it up for adoption. - * - * XXX: We should also check nhttp + * Report and dismantle a session. */ void @@ -338,27 +333,18 @@ SES_Delete(struct sess *sp, enum sess_close reason, double now) if (reason != SC_NULL) SES_Close(sp, reason); + assert(sp->fd < 0); + if (isnan(now)) now = VTIM_real(); assert(!isnan(sp->t_open)); - assert(sp->fd < 0); - - if (*sp->addr == '\0') - strcpy(sp->addr, "-"); - if (*sp->port == '\0') - strcpy(sp->addr, "-"); b = &sp->acct_ses; - - VSL(SLT_SessClose, sp->vxid, - "%s %.3f %ju %ju %ju %ju %ju %ju", - sess_close_str(sp->reason, 0), - now - sp->t_open, - b->req, b->pipe, b->pass, - b->fetch, b->hdrbytes, b->bodybytes); + VSL(SLT_SessClose, sp->vxid, "%s %.3f %ju %ju %ju %ju %ju %ju", + sess_close_str(sp->reason, 0), now - sp->t_open, b->req, + b->pipe, b->pass, b->fetch, b->hdrbytes, b->bodybytes); MPL_Free(pp->mpl_sess, sp); - } /*-------------------------------------------------------------------- From martin at varnish-cache.org Thu Jul 19 08:37:29 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 19 Jul 2012 10:37:29 +0200 Subject: [master] c22afc8 Do not consider busy objects as candidates in EXP_NukeOne. Message-ID: commit c22afc8a73d3e55831e06293c4b2f42a7e15b9e8 Author: Martin Blix Grydeland Date: Wed Jul 4 13:25:08 2012 +0200 Do not consider busy objects as candidates in EXP_NukeOne. An attempt to nuke a busy object will end in assertion. diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c index 5a41875..8f072b6 100644 --- a/bin/varnishd/cache/cache_expire.c +++ b/bin/varnishd/cache/cache_expire.c @@ -428,9 +428,10 @@ EXP_NukeOne(struct busyobj *bo, struct lru *lru) /* * It wont release any space if we cannot release the last * reference, besides, if somebody else has a reference, - * it's a bad idea to nuke this object anyway. + * it's a bad idea to nuke this object anyway. Also do not + * touch busy objects. */ - if (oc->refcnt == 1) + if (oc->refcnt == 1 && !(oc->flags & OC_F_BUSY)) break; } if (oc != NULL) { From martin at varnish-cache.org Thu Jul 19 08:37:29 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 19 Jul 2012 10:37:29 +0200 Subject: [master] 116393f Do not try to expire objects that are still busy. Message-ID: commit 116393f289258b2bb9b49d518b0206cec6550a75 Author: Martin Blix Grydeland Date: Wed Jul 4 13:07:15 2012 +0200 Do not try to expire objects that are still busy. There is a short window of opportunity between HSH_Insert() and HSH_Unbusy(), where the locks are released and the expiry thread can try to expire an object that is still busy (for objects with very short TTL). This patch makes the expiry thread check for busy objects and wait if the head of the binheap is busy. No test case as the window is too small. Fixes: #1150 diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c index 8f072b6..3d18d78 100644 --- a/bin/varnishd/cache/cache_expire.c +++ b/bin/varnishd/cache/cache_expire.c @@ -369,6 +369,13 @@ exp_timer(struct worker *wrk, void *priv) continue; } + /* If the object is busy, we have to wait for it */ + if (oc->flags & OC_F_BUSY) { + Lck_Unlock(&exp_mtx); + oc = NULL; + continue; + } + /* * It's time... * Technically we should drop the exp_mtx, get the lru->mtx From martin at varnish-cache.org Thu Jul 19 08:37:29 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 19 Jul 2012 10:37:29 +0200 Subject: [master] 0c9975c Make the ban lurker skip busy objects Message-ID: commit 0c9975c1be926799c368d904dd65204eca25ed50 Author: Martin Blix Grydeland Date: Wed Jul 4 13:02:55 2012 +0200 Make the ban lurker skip busy objects If the ban lurker finds a busy object, skip the object and defer the checking to a later pass. No test case because it is very timing sensitive (but see the trac bug report for a VTC-file that mostly triggers it on the 3.0 branch only) Fixes: #1162 diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index be8af1a..4164e4b 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -879,6 +879,18 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl, unsigned pass) continue; } /* + * If the object is busy, we can't touch + * it. Defer it to a later run. + */ + if (oc->flags & OC_F_BUSY) { + oc->flags |= pass; + VTAILQ_REMOVE(&b->objcore, oc, ban_list); + VTAILQ_INSERT_TAIL(&b->objcore, oc, ban_list); + Lck_Unlock(&oh->mtx); + Lck_Unlock(&ban_mtx); + continue; + } + /* * Grab a reference to the OC and we can let go of * the BAN mutex */ From martin at varnish-cache.org Thu Jul 19 08:41:28 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 19 Jul 2012 10:41:28 +0200 Subject: [3.0] d1ba932 Do not consider busy objects as candidates in EXP_NukeOne. Message-ID: commit d1ba9327229e1b0a3cec78ad4071e9796f6b70a8 Author: Martin Blix Grydeland Date: Wed Jul 4 13:25:08 2012 +0200 Do not consider busy objects as candidates in EXP_NukeOne. An attempt to nuke a busy object will end in assertion. diff --git a/bin/varnishd/cache_expire.c b/bin/varnishd/cache_expire.c index 7fa48da..15482bf 100644 --- a/bin/varnishd/cache_expire.c +++ b/bin/varnishd/cache_expire.c @@ -431,9 +431,10 @@ EXP_NukeOne(struct worker *w, struct lru *lru) /* * It wont release any space if we cannot release the last * reference, besides, if somebody else has a reference, - * it's a bad idea to nuke this object anyway. + * it's a bad idea to nuke this object anyway. Also do not + * touch busy objects. */ - if (oc->refcnt == 1) + if (oc->refcnt == 1 && !(oc->flags & OC_F_BUSY)) break; } if (oc != NULL) { From martin at varnish-cache.org Thu Jul 19 08:41:28 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 19 Jul 2012 10:41:28 +0200 Subject: [3.0] ef93091 Do not try to expire objects that are still busy. Message-ID: commit ef930917740c3f2b81d8c08219d99dcc7bd3dc60 Author: Martin Blix Grydeland Date: Wed Jul 4 13:07:15 2012 +0200 Do not try to expire objects that are still busy. There is a short window of opportunity between HSH_Insert() and HSH_Unbusy(), where the locks are released and the expiry thread can try to expire an object that is still busy (for objects with very short TTL). This patch makes the expiry thread check for busy objects and wait if the head of the binheap is busy. No test case as the window is too small. Fixes: #1150 diff --git a/bin/varnishd/cache_expire.c b/bin/varnishd/cache_expire.c index 15482bf..5dbafa6 100644 --- a/bin/varnishd/cache_expire.c +++ b/bin/varnishd/cache_expire.c @@ -371,6 +371,13 @@ exp_timer(struct sess *sp, void *priv) continue; } + /* If the object is busy, we have to wait for it */ + if (oc->flags & OC_F_BUSY) { + Lck_Unlock(&exp_mtx); + oc = NULL; + continue; + } + /* * It's time... * Technically we should drop the exp_mtx, get the lru->mtx From martin at varnish-cache.org Thu Jul 19 08:41:28 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 19 Jul 2012 10:41:28 +0200 Subject: [3.0] a71c7de Make the ban lurker skip busy objects Message-ID: commit a71c7de8a15452368de76c384c7d26c5b775bb79 Author: Martin Blix Grydeland Date: Wed Jul 4 13:02:55 2012 +0200 Make the ban lurker skip busy objects If the ban lurker finds a busy object, skip the object and defer the checking to a later pass. No test case because it is very timing sensitive (but see the trac bug report for a VTC-file that mostly triggers it on the 3.0 branch only) Fixes: #1162 diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c index bab278d..5c1da57 100644 --- a/bin/varnishd/cache_ban.c +++ b/bin/varnishd/cache_ban.c @@ -838,6 +838,18 @@ ban_lurker_work(const struct sess *sp, unsigned pass) continue; } /* + * If the object is busy, we can't touch + * it. Defer it to a later run. + */ + if (oc->flags & OC_F_BUSY) { + oc->flags |= pass; + VTAILQ_REMOVE(&b->objcore, oc, ban_list); + VTAILQ_INSERT_TAIL(&b->objcore, oc, ban_list); + Lck_Unlock(&oh->mtx); + Lck_Unlock(&ban_mtx); + continue; + } + /* * Grab a reference to the OC and we can let go of * the BAN mutex */ From tfheen at varnish-cache.org Thu Jul 19 12:27:19 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 19 Jul 2012 14:27:19 +0200 Subject: [master] 8d1a7b8 Test commit to check trac hooks Message-ID: commit 8d1a7b8461db6508d6e3e4f4138cf9059e0de784 Author: Tollef Fog Heen Date: Thu Jul 19 14:27:13 2012 +0200 Test commit to check trac hooks diff --git a/Makefile.am b/Makefile.am index dad3621..44b2481 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,3 @@ -# - ACLOCAL_AMFLAGS = -I m4 SUBDIRS = include lib bin man etc doc From tfheen at varnish-cache.org Thu Jul 19 12:30:13 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 19 Jul 2012 14:30:13 +0200 Subject: [master] 5d976a5 INSTALL: minor update Message-ID: commit 5d976a5d500df0b59226606db05a17269bba87ea Author: Tollef Fog Heen Date: Thu Jul 19 14:30:10 2012 +0200 INSTALL: minor update diff --git a/INSTALL b/INSTALL index ca9f152..97b2502 100644 --- a/INSTALL +++ b/INSTALL @@ -5,8 +5,8 @@ run the 'configure' script in the top-level directory, then run 'make' and 'make install'. On Linux, you need to run 'ldconfig' as root afterwards in order to update the shared library cache. -If you obtained the sources directly from the Subversion repository, -you will need to run autogen.sh first to create the configure script. +If you obtained the sources directly from the Git repository, you will +need to run autogen.sh first to create the configure script. Varnish will store run-time state in $localstatedir/varnish; you may want to tune this using configure's --localstatedir parameter. From martin at varnish-cache.org Fri Jul 20 10:41:18 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Fri, 20 Jul 2012 12:41:18 +0200 Subject: [master] f9c42ca Extend cli_limit to 48k to make room for the full output of 'param.show -l'. Message-ID: commit f9c42ca8306792ceb1d52cb78c4af23b7ee474af Author: Martin Blix Grydeland Date: Fri Jul 20 12:35:56 2012 +0200 Extend cli_limit to 48k to make room for the full output of 'param.show -l'. Fixes: #1169 diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index b030caa..2f090dc 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -908,7 +908,7 @@ static const struct parspec input_parspec[] = { " this limit, the reponse code will be 201 instead of" " 200 and the last line will indicate the truncation.", 0, - "4k", "bytes" }, + "48k", "bytes" }, { "cli_timeout", tweak_timeout, &mgt_param.cli_timeout, 0, 0, "Timeout for the childs replies to CLI requests from " "the mgt_param.", diff --git a/bin/varnishtest/tests/r01169.vtc b/bin/varnishtest/tests/r01169.vtc new file mode 100644 index 0000000..73e741d --- /dev/null +++ b/bin/varnishtest/tests/r01169.vtc @@ -0,0 +1,9 @@ +varnishtest "cli_limit truncating full parameter listing - #1169" + +server s1 { + rxreq +} -start + +varnish v1 -vcl+backend { } + +varnish v1 -cliok "param.show -l" From lkarsten at varnish-cache.org Fri Jul 20 10:47:34 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Fri, 20 Jul 2012 12:47:34 +0200 Subject: [3.0] 9d09170 Regex set for doing device detection Message-ID: commit 9d09170bdca2018cca44d28714ed4b81b6029c2f Author: Lasse Karstensen Date: Fri Jul 20 12:47:06 2012 +0200 Regex set for doing device detection diff --git a/etc/devicedetect.vcl b/etc/devicedetect.vcl new file mode 100644 index 0000000..ed5b39d --- /dev/null +++ b/etc/devicedetect.vcl @@ -0,0 +1,69 @@ +# +# detectdevice.vcl - regex based device detection for Varnish +# http://github.com/varnish/varnish-devicedetect/ +# +# Author: Lasse Karstensen + +sub devicedetect { + unset req.http.X-UA-Device; + set req.http.X-UA-Device = "pc"; + + if (req.http.User-Agent ~ "(?i)(ads|google|bing|msn|yandex|baidu|ro|career|)bot" || + req.http.User-Agent ~ "(?i)(baidu|symantec)spider" || + req.http.User-Agent ~ "(?i)scanner" || + req.http.User-Agent ~ "(?i)(web)crawler") { + set req.http.X-UA-Device = "bot"; } + elsif (req.http.User-Agent ~ "(?i)ip(hone|od)") { set req.http.X-UA-Device = "mobile-iphone"; } + elsif (req.http.User-Agent ~ "(?i)ipad") { set req.http.X-UA-Device = "tablet-ipad"; } + # how do we differ between an android phone and an android tablet? + # http://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent + elsif (req.http.User-Agent ~ "(?i)android.*(mobile|mini)") { set req.http.X-UA-Device = "mobile-android"; } + # android 3/honeycomb was just about tablet-only, and any phones will probably handle a bigger page layout. + elsif (req.http.User-Agent ~ "(?i)android 3") { set req.http.X-UA-Device = "tablet-android"; } + # may very well give false positives towards android tablets. Suggestions welcome. + elsif (req.http.User-Agent ~ "(?i)android") { set req.http.X-UA-Device = "tablet-android"; } + + elsif (req.http.User-Agent ~ "^HTC" || + req.http.User-Agent ~ "Fennec" || + req.http.User-Agent ~ "IEMobile" || + req.http.User-Agent ~ "BlackBerry" || + req.http.User-Agent ~ "SymbianOS.*AppleWebKit" || + req.http.User-Agent ~ "Opera Mobi") { + set req.http.X-UA-Device = "mobile-smartphone"; + } + elsif (req.http.User-Agent ~ "(?i)symbian" || + req.http.User-Agent ~ "(?i)^sonyericsson" || + req.http.User-Agent ~ "(?i)^nokia" || + req.http.User-Agent ~ "(?i)^samsung" || + req.http.User-Agent ~ "(?i)^lg" || + req.http.User-Agent ~ "(?i)bada" || + req.http.User-Agent ~ "(?i)blazer" || + req.http.User-Agent ~ "(?i)cellphone" || + req.http.User-Agent ~ "(?i)iemobile" || + req.http.User-Agent ~ "(?i)midp-2.0" || + req.http.User-Agent ~ "(?i)u990" || + req.http.User-Agent ~ "(?i)netfront" || + req.http.User-Agent ~ "(?i)opera mini" || + req.http.User-Agent ~ "(?i)palm" || + req.http.User-Agent ~ "(?i)nintendo wii" || + req.http.User-Agent ~ "(?i)playstation portable" || + req.http.User-Agent ~ "(?i)portalmmm" || + req.http.User-Agent ~ "(?i)proxinet" || + req.http.User-Agent ~ "(?i)sonyericsson" || + req.http.User-Agent ~ "(?i)symbian" || + req.http.User-Agent ~ "(?i)windows\ ?ce" || + req.http.User-Agent ~ "(?i)winwap" || + req.http.User-Agent ~ "(?i)eudoraweb" || + req.http.User-Agent ~ "(?i)htc" || + req.http.User-Agent ~ "(?i)240x320" || + req.http.User-Agent ~ "(?i)avantgo") { + set req.http.X-UA-Device = "mobile-generic"; + } + # handle overrides + if (req.http.Cookie ~ "(i?)X-UA-Device-force") { + # ;?? means zero or one ;, non-greedy to match the first. + set req.http.X-UA-Device = regsub(req.http.Cookie, "(?i).*X-UA-Device-force=([^;]+);??.*", "\1"); + } +} + +# vim: sw=4:tw=120 # meh From lkarsten at varnish-cache.org Fri Jul 20 10:48:52 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Fri, 20 Jul 2012 12:48:52 +0200 Subject: [master] acc8909 Regex set for doing device detection Message-ID: commit acc8909f7439d55a085d90b879b57db46bc4da13 Author: Lasse Karstensen Date: Fri Jul 20 12:47:06 2012 +0200 Regex set for doing device detection diff --git a/etc/devicedetect.vcl b/etc/devicedetect.vcl new file mode 100644 index 0000000..ed5b39d --- /dev/null +++ b/etc/devicedetect.vcl @@ -0,0 +1,69 @@ +# +# detectdevice.vcl - regex based device detection for Varnish +# http://github.com/varnish/varnish-devicedetect/ +# +# Author: Lasse Karstensen + +sub devicedetect { + unset req.http.X-UA-Device; + set req.http.X-UA-Device = "pc"; + + if (req.http.User-Agent ~ "(?i)(ads|google|bing|msn|yandex|baidu|ro|career|)bot" || + req.http.User-Agent ~ "(?i)(baidu|symantec)spider" || + req.http.User-Agent ~ "(?i)scanner" || + req.http.User-Agent ~ "(?i)(web)crawler") { + set req.http.X-UA-Device = "bot"; } + elsif (req.http.User-Agent ~ "(?i)ip(hone|od)") { set req.http.X-UA-Device = "mobile-iphone"; } + elsif (req.http.User-Agent ~ "(?i)ipad") { set req.http.X-UA-Device = "tablet-ipad"; } + # how do we differ between an android phone and an android tablet? + # http://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent + elsif (req.http.User-Agent ~ "(?i)android.*(mobile|mini)") { set req.http.X-UA-Device = "mobile-android"; } + # android 3/honeycomb was just about tablet-only, and any phones will probably handle a bigger page layout. + elsif (req.http.User-Agent ~ "(?i)android 3") { set req.http.X-UA-Device = "tablet-android"; } + # may very well give false positives towards android tablets. Suggestions welcome. + elsif (req.http.User-Agent ~ "(?i)android") { set req.http.X-UA-Device = "tablet-android"; } + + elsif (req.http.User-Agent ~ "^HTC" || + req.http.User-Agent ~ "Fennec" || + req.http.User-Agent ~ "IEMobile" || + req.http.User-Agent ~ "BlackBerry" || + req.http.User-Agent ~ "SymbianOS.*AppleWebKit" || + req.http.User-Agent ~ "Opera Mobi") { + set req.http.X-UA-Device = "mobile-smartphone"; + } + elsif (req.http.User-Agent ~ "(?i)symbian" || + req.http.User-Agent ~ "(?i)^sonyericsson" || + req.http.User-Agent ~ "(?i)^nokia" || + req.http.User-Agent ~ "(?i)^samsung" || + req.http.User-Agent ~ "(?i)^lg" || + req.http.User-Agent ~ "(?i)bada" || + req.http.User-Agent ~ "(?i)blazer" || + req.http.User-Agent ~ "(?i)cellphone" || + req.http.User-Agent ~ "(?i)iemobile" || + req.http.User-Agent ~ "(?i)midp-2.0" || + req.http.User-Agent ~ "(?i)u990" || + req.http.User-Agent ~ "(?i)netfront" || + req.http.User-Agent ~ "(?i)opera mini" || + req.http.User-Agent ~ "(?i)palm" || + req.http.User-Agent ~ "(?i)nintendo wii" || + req.http.User-Agent ~ "(?i)playstation portable" || + req.http.User-Agent ~ "(?i)portalmmm" || + req.http.User-Agent ~ "(?i)proxinet" || + req.http.User-Agent ~ "(?i)sonyericsson" || + req.http.User-Agent ~ "(?i)symbian" || + req.http.User-Agent ~ "(?i)windows\ ?ce" || + req.http.User-Agent ~ "(?i)winwap" || + req.http.User-Agent ~ "(?i)eudoraweb" || + req.http.User-Agent ~ "(?i)htc" || + req.http.User-Agent ~ "(?i)240x320" || + req.http.User-Agent ~ "(?i)avantgo") { + set req.http.X-UA-Device = "mobile-generic"; + } + # handle overrides + if (req.http.Cookie ~ "(i?)X-UA-Device-force") { + # ;?? means zero or one ;, non-greedy to match the first. + set req.http.X-UA-Device = regsub(req.http.Cookie, "(?i).*X-UA-Device-force=([^;]+);??.*", "\1"); + } +} + +# vim: sw=4:tw=120 # meh From apj at varnish-cache.org Fri Jul 27 12:59:42 2012 From: apj at varnish-cache.org (Andreas Plesner Jacobsen) Date: Fri, 27 Jul 2012 14:59:42 +0200 Subject: [3.0] 1223d71 Changelog for 3.0.3 Message-ID: commit 1223d711bd580fa14612734cf70d2dc3cac860f8 Author: Andreas Plesner Jacobsen Date: Fri Jul 27 14:59:36 2012 +0200 Changelog for 3.0.3 diff --git a/doc/changes.rst b/doc/changes.rst index 8659f2e..1035f88 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,3 +1,123 @@ +=========================== +Changes from 3.0.2 to 3.0.3 +=========================== + +Varnishd +-------- + +- Fix an issue where the bodybytes counter is not updated correctly on + gunzipped delivery. +- Fix a race on the n_sess counter. This race made varnish do excessive + session workspace allocations. `Bug #897`_. +- Fix some crashes in the gzip code when it runs out of memory. `Bug #1037`_. + `Bug #1043`_. `Bug #1044`_. +- Fix a bug where the regular expression parser could end up in an infinite + loop. `Bug #1047`_. +- Fix a memory leak in the regex code. +- DNS director now uses port 80 by default if not specified. +- Introduce `idle_send_timeout` and increase default value for `send_timeout` + to 600s. This allows a long send timeout for slow clients while still being + able to disconnect idle clients. +- Fix an issue where did not remove HTML comments. `Bug #1092`_. +- Fix a crash when passing with streaming on. +- Fix a crash in the idle session timeout code. +- Fix an issue where the poll waiter did not timeout clients if all clients + were idle. `Bug #1023`_. +- Log regex errors instead of crashing. +- Introduce `pcre_match_limit`, and `pcre_match_limit_recursion` parameters. +- Add CLI commands to manually control health state of a backend. +- Fix an issue where the s_bodybytes counter is not updated correctly on + gunzipped delivery. +- Fix a race on the n_sess counter that leads to increased session object + allocation. `Bug #897`_. +- Fix a crash when we couldn't allocate memory for a fetched object. + `Bug #1100`_. +- Fix an issue where objects could end up in the transient store with a + long TTL, when memory could not be allocated for them in the requested + store. `Bug #1140`_. +- Activate req.hash_ignore_busy when req.hash_always_miss is activated. + `Bug #1073`_. +- Reject invalid tcp port numbers for listen address. `Bug #1035`_. +- Enable JIT for better performing regular expressions. `Bug #1080`_. +- Return VCL errors in exit code when using -C. `Bug #1069`_. +- Stricter validation of acl syntax, to avoid a crash with 5-octet IPv4 + addresses. `Bug #1126`_. +- Fix a crash when first argument to regsub was null. `Bug #1125`_. +- Fix a case where varnish delivered corrupt gzip content when using ESI. + `Bug #1109`_. +- Fix a case where varnish didn't remove the old Date header and served + it alongside the varnish-generated Date header. `Bug #1104`_. +- Make saint mode work, for the case where we have no object with that hash. + `Bug #1091`_. +- Don't save the object body on hit-for-pass objects. +- n_ban_gone counter added to count the number of "gone" bans. +- Ban lurker rewritten to properly sleep when no bans are present, and + otherwise to process the list at the configured speed. +- Fix a case where varnish delivered wrong content for an uncompressed page + with compressed ESI child. `Bug #1029`_. +- Fix an issue where varnish runs out of thread workspace when processing + many ESI includes on an object. `Bug #1038`_. +- Fix a crash when streaming was enabled for an empty body. +- Better error reporting for some fetch errors. +- Small performance optimizations. + +.. _bug #897: http://varnish-cache.org/trac/ticket/897 +.. _bug #1023: http://varnish-cache.org/trac/ticket/1023 +.. _bug #1029: http://varnish-cache.org/trac/ticket/1029 +.. _bug #1023: http://varnish-cache.org/trac/ticket/1023 +.. _bug #1035: http://varnish-cache.org/trac/ticket/1035 +.. _bug #1037: http://varnish-cache.org/trac/ticket/1037 +.. _bug #1038: http://varnish-cache.org/trac/ticket/1038 +.. _bug #1043: http://varnish-cache.org/trac/ticket/1043 +.. _bug #1044: http://varnish-cache.org/trac/ticket/1044 +.. _bug #1047: http://varnish-cache.org/trac/ticket/1047 +.. _bug #1069: http://varnish-cache.org/trac/ticket/1069 +.. _bug #1073: http://varnish-cache.org/trac/ticket/1073 +.. _bug #1080: http://varnish-cache.org/trac/ticket/1080 +.. _bug #1091: http://varnish-cache.org/trac/ticket/1091 +.. _bug #1092: http://varnish-cache.org/trac/ticket/1092 +.. _bug #1100: http://varnish-cache.org/trac/ticket/1100 +.. _bug #1104: http://varnish-cache.org/trac/ticket/1104 +.. _bug #1109: http://varnish-cache.org/trac/ticket/1109 +.. _bug #1125: http://varnish-cache.org/trac/ticket/1125 +.. _bug #1126: http://varnish-cache.org/trac/ticket/1126 +.. _bug #1140: http://varnish-cache.org/trac/ticket/1140 + +varnishncsa +----------- + +- Support for \t\n in varnishncsa format strings. +- Add new format: %{VCL_Log:foo}x which output key:value from std.log() in + VCL. +- Add user-defined date formatting, using %{format}t. + +varnishtest +----------- + +- resp.body is now available for inspection. +- Make it possible to test for the absence of an HTTP header. `Bug #1062`_. +- Log the full panic message instead of shortening it to 512 characters. + +.. _bug #1062: http://varnish-cache.org/trac/ticket/1062 + +varnishstat +----------- + +- Add json output (-j). + +Other +----- + +- Documentation updates. +- Bump minimum number of threads to 50 in RPM packages. +- RPM packaging updates. +- Fix some compilation warnings on Solaris. +- Fix some build issues on Open/Net/DragonFly-BSD. +- Fix build on FreeBSD 10-current. +- Fix libedit detection on \*BSD OSes. `Bug #1003`_. + +.. _bug #1003: http://varnish-cache.org/trac/ticket/1003 + ================================ Changes from 3.0.2 rc 1 to 3.0.2 ================================ @@ -60,10 +180,11 @@ Varnishd .. _bug #994: http://varnish-cache.org/trac/ticket/994 .. _bug #992: http://varnish-cache.org/trac/ticket/992 +.. _bug #996: http://varnish-cache.org/trac/ticket/996 .. _bug #1007: http://varnish-cache.org/trac/ticket/1007 .. _bug #1008: http://varnish-cache.org/trac/ticket/1008 .. _bug #1012: http://varnish-cache.org/trac/ticket/1012 -.. _bug #1012: http://varnish-cache.org/trac/ticket/1016 +.. _bug #1016: http://varnish-cache.org/trac/ticket/1016 VCL --- From phk at varnish-cache.org Mon Jul 30 09:17:22 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 30 Jul 2012 11:17:22 +0200 Subject: [master] 73d989b Patch from Geoff: Message-ID: commit 73d989b5ccf1056399c3fe3e05ccf036f175c5f6 Author: Poul-Henning Kamp Date: Mon Jul 30 09:15:06 2012 +0000 Patch from Geoff: Fixes a compile error (incorrect signature for SES_Delete() in cache_waiter_ports.c) diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c index 87eaeac..af5d965 100644 --- a/bin/varnishd/waiter/cache_waiter_ports.c +++ b/bin/varnishd/waiter/cache_waiter_ports.c @@ -80,14 +80,13 @@ vws_port_ev(struct vws *vws, port_event_t *ev, double now) { VTAILQ_INSERT_TAIL(&vws->sesshead, sp, list); vws_add(vws, sp->fd, sp); } else { - int i; assert(ev->portev_source == PORT_SOURCE_FD); CAST_OBJ_NOTNULL(sp, ev->portev_user, SESS_MAGIC); assert(sp->fd >= 0); if(ev->portev_events & POLLERR) { vws_del(vws, sp->fd); VTAILQ_REMOVE(&vws->sesshead, sp, list); - SES_Delete(sp, "EOF", now); + SES_Delete(sp, SC_REM_CLOSE, now); return; } @@ -211,7 +210,7 @@ vws_thread(void *priv) if(sp->fd != -1) { vws_del(vws, sp->fd); } - SES_Delete(sp, "timeout", now); + SES_Delete(sp, SC_RX_TIMEOUT, now); } /* From phk at varnish-cache.org Mon Jul 30 15:07:13 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 30 Jul 2012 17:07:13 +0200 Subject: [master] 15330c9 Make the sandbox interface more modular and tell the implementation which subprocess we are locking down. Message-ID: commit 15330c9023befc6653bec269eabb0576b61732cf Author: Poul-Henning Kamp Date: Mon Jul 30 15:05:25 2012 +0000 Make the sandbox interface more modular and tell the implementation which subprocess we are locking down. Inspired by Geoff's patch for Solaris, but does not solve the Solaris problem, only makes it easier to fix. diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 6478a00..a521f6f 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -179,7 +179,7 @@ ses_sess_pool_task(struct worker *wrk, void *arg) * VSL comes before anything else for this session. * * This is a separate procedure only to isolate the two stack buffers. - * + * */ static void diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 512c6dc..905fbcc 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -74,13 +74,19 @@ void MCF_DumpRstParam(void); extern struct params mgt_param; /* mgt_sandbox.c */ -void mgt_sandbox(void); +enum sandbox_e { + SANDBOX_VCC = 1, + SANDBOX_CC = 2, + SANDBOX_VCLLOAD = 3, + SANDBOX_WORKER = 4, +}; + +typedef void mgt_sandbox_f(enum sandbox_e); +extern mgt_sandbox_f *mgt_sandbox; /* mgt_sandbox_solaris.c */ #ifdef HAVE_SETPPRIV -void mgt_sandbox_solaris_init(void); -void mgt_sandbox_solaris_fini(void); -void mgt_sandbox_solaris_privsep(void); +mgt_sandbox_f mgt_sandbox_solaris; #endif /* mgt_shmem.c */ diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index 8661b73..c869897 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -338,7 +338,7 @@ start_child(struct cli *cli) (void)signal(SIGINT, SIG_DFL); (void)signal(SIGTERM, SIG_DFL); - mgt_sandbox(); + mgt_sandbox(SANDBOX_WORKER); child_main(); diff --git a/bin/varnishd/mgt/mgt_sandbox.c b/bin/varnishd/mgt/mgt_sandbox.c index 3cd1d98..bf9802f 100644 --- a/bin/varnishd/mgt/mgt_sandbox.c +++ b/bin/varnishd/mgt/mgt_sandbox.c @@ -59,32 +59,41 @@ /* Waive all privileges in the child, it does not need any */ -void -mgt_sandbox(void) +static void __match_proto__(mgt_sandbox_f) +mgt_sandbox_unix(enum sandbox_e who) { -#ifdef HAVE_SETPPRIV - mgt_sandbox_solaris_init(); - mgt_sandbox_solaris_privsep(); -#else + (void)who; if (geteuid() == 0) { XXXAZ(setgid(mgt_param.gid)); XXXAZ(setuid(mgt_param.uid)); } else { REPORT0(LOG_INFO, "Not running as root, no priv-sep"); } -#endif +} - /* On Linux >= 2.4, you need to set the dumpable flag - to get core dumps after you have done a setuid. */ +/*--------------------------------------------------------------------*/ #ifdef __linux__ - if (prctl(PR_SET_DUMPABLE, 1) != 0) +static void __match_proto__(mgt_sandbox_f) +mgt_sandbox_linux(enum sandbox_e who) +{ + mgt_sandbox_unix(who); + + if (prctl(PR_SET_DUMPABLE, 1) != 0) { REPORT0(LOG_INFO, "Could not set dumpable bit. Core dumps turned off\n"); + } +} #endif -#ifdef HAVE_SETPPRIV - mgt_sandbox_solaris_fini(); -#endif -} +/*--------------------------------------------------------------------*/ + +mgt_sandbox_f *mgt_sandbox = +#ifdef HAVE_SETPRIV + mgt_sandbox_solaris; +#elif defined (__linux__) + mgt_sandbox_linux; +#else + mgt_sandbox_unix; +#endif diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index 6f4642d..f7f199a 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -137,7 +137,7 @@ run_vcc(void *priv) int fd, i, l; CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC); - mgt_sandbox(); + mgt_sandbox(SANDBOX_VCC); sb = VSB_new_auto(); XXXAN(sb); VCC_VCL_dir(vcc, mgt_vcl_dir); @@ -176,7 +176,7 @@ run_vcc(void *priv) static void run_cc(void *priv) { - mgt_sandbox(); + mgt_sandbox(SANDBOX_CC); (void)execl("/bin/sh", "/bin/sh", "-c", priv, NULL); } @@ -193,7 +193,7 @@ run_dlopen(void *priv) of = priv; - mgt_sandbox(); + mgt_sandbox(SANDBOX_VCLLOAD); /* Try to load the object into this sub-process */ if ((dlh = dlopen(of, RTLD_NOW | RTLD_LOCAL)) == NULL) { From phk at varnish-cache.org Mon Jul 30 15:17:57 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 30 Jul 2012 17:17:57 +0200 Subject: [master] d5c5d5b Sigh... Message-ID: commit d5c5d5b68cd62b633c25e44ff3bd9d93985c78d6 Author: Poul-Henning Kamp Date: Mon Jul 30 15:17:12 2012 +0000 Sigh... It was a nice idea, but obviously compiler-writers and/or language laywers are pussies who hate table-based programming :-) diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 37c2e6b..ae83bf7 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -75,18 +75,19 @@ SLTM(SessOpen, "Client connection opened", "lport\n Local TCP port ('-' if !$log_local_addr)\n\n" ) +/* + * XXX: compilers are _so_ picky, and won't let us do an #include + * XXX: in the middle of a macro invocation :-( + * XXX: If we could, these three lines would have described the + * XXX: 'reason' field below. #define SESS_CLOSE(nm, desc) " " #nm "\n\t" desc "\n\n" +#include +#undef SESS_CLOSE +*/ SLTM(SessClose, "Client connection closed", "SessionClose is the last record for any client connection.\n\n" "reason\n Why the connection closed.\n\n" -#ifdef __clang__ -/* - * GCC barfs at this construct, but we have no way to ask compiler - * if it is _not_ a GCC compiler since CLANG also defines __GNUC__ - */ -#include -#endif "duration\n How long the session were open.\n\n" "Nreq\n How many requests on session.\n\n" "Npipe\n If 'pipe' were used on session.\n\n" @@ -95,7 +96,6 @@ SLTM(SessClose, "Client connection closed", "Bhdr\n Header bytes sent on session.\n\n" "Bbody\n Body bytes sent on session.\n\n" ) -#undef SESS_CLOSE /*---------------------------------------------------------------------*/ From phk at varnish-cache.org Mon Jul 30 15:53:49 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 30 Jul 2012 17:53:49 +0200 Subject: [master] 610d3cb I have no idea how I ended up incrementting the fail counter by the size of the request, probably sleep copy&paste ? Message-ID: commit 610d3cbee4fd6b1e2ca6c84ef385beae07f56144 Author: Poul-Henning Kamp Date: Mon Jul 30 15:52:55 2012 +0000 I have no idea how I ended up incrementting the fail counter by the size of the request, probably sleep copy&paste ? Fixed #1175 Submitted by: martin diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c index 0470093..88cb948 100644 --- a/bin/varnishd/storage/storage_malloc.c +++ b/bin/varnishd/storage/storage_malloc.c @@ -67,7 +67,7 @@ sma_alloc(struct stevedore *st, size_t size) Lck_Lock(&sma_sc->sma_mtx); sma_sc->stats->c_req++; if (sma_sc->sma_alloc + size > sma_sc->sma_max) { - sma_sc->stats->c_fail += size; + sma_sc->stats->c_fail++; size = 0; } else { sma_sc->sma_alloc += size; diff --git a/bin/varnishtest/tests/r01175.vtc b/bin/varnishtest/tests/r01175.vtc new file mode 100644 index 0000000..739c56a --- /dev/null +++ b/bin/varnishtest/tests/r01175.vtc @@ -0,0 +1,20 @@ +varnishtest "#1175 - -smalloc c_fail incremented by bytes" + +server s1 { + rxreq + txresp -nolen -hdr "Content-Length: 1048576" +} -start + +varnish v1 -storage "-s test=malloc,1M" -vcl+backend { + sub vcl_fetch { + set beresp.storage = "test"; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + +varnish v1 -expect SMA.test.c_fail < 5 From phk at varnish-cache.org Mon Jul 30 16:35:51 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 30 Jul 2012 18:35:51 +0200 Subject: [master] ffa30f0 Change our chosen "bad_ip" to 192.0.2.255 which is a broadcast address from RFC5737's TEST-NET-1 and put a comment there to explain. Message-ID: commit ffa30f0490d6e2b59204757ddbdc7f032d64ce3a Author: Poul-Henning Kamp Date: Mon Jul 30 16:33:48 2012 +0000 Change our chosen "bad_ip" to 192.0.2.255 which is a broadcast address from RFC5737's TEST-NET-1 and put a comment there to explain. I fear this is a loosing battle, but at least this is more "official" than the previous "10.255.255.255" choice. Fixes #1159 diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index 99cf840..a2c0571 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -563,7 +563,15 @@ exec_file(const char *fn, const char *script, const char *tmpdir, cwd = getcwd(NULL, PATH_MAX); macro_def(vltop, NULL, "pwd", "%s", cwd); macro_def(vltop, NULL, "topbuild", "%s/%s", cwd, TOP_BUILDDIR); - macro_def(vltop, NULL, "bad_ip", "10.255.255.255"); + + /* + * We need an IP number which will not repond, ever, and that is a + * lot harder than it sounds. This IP# is from RFC5737 and a + * C-class broadcast at that. + * If tests involving ${bad_ip} fails and you run linux, you should + * check your /proc/sys/net/ipv4/ip_nonlocal_bind setting. + */ + macro_def(vltop, NULL, "bad_ip", "192.0.2.255"); /* Move into our tmpdir */ AZ(chdir(tmpdir)); From phk at varnish-cache.org Tue Jul 31 08:06:07 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 31 Jul 2012 10:06:07 +0200 Subject: [master] feac371 Don't do automatic backend retry if we have received anything from the backend at all. The retry is only (pseudo-)valid when we have not received anything at all, indicating that the backend closed before it got our request. Message-ID: commit feac37150e5820cb36b0181811a47b957cd9b51c Author: Poul-Henning Kamp Date: Tue Jul 31 08:04:15 2012 +0000 Don't do automatic backend retry if we have received anything from the backend at all. The retry is only (pseudo-)valid when we have not received anything at all, indicating that the backend closed before it got our request. Also don't retry if we sent the request body (not part of test-case). Fixes #1156 diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 3b9b08d..1d97c51 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -480,6 +480,8 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody) /* Deal with any message-body the request might have */ i = FetchReqBody(req, sendbody); + if (sendbody && req->reqbodydone) + retry = -1; if (WRW_FlushRelease(wrk) || i > 0) { VSLb(req->vsl, SLT_FetchError, "backend write error: %d (%s)", @@ -520,6 +522,7 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody) return (retry); } if (first) { + retry = -1; first = 0; VTCP_set_read_timeout(vc->fd, vc->between_bytes_timeout); diff --git a/bin/varnishtest/tests/r01156.vtc b/bin/varnishtest/tests/r01156.vtc new file mode 100644 index 0000000..2624ddd --- /dev/null +++ b/bin/varnishtest/tests/r01156.vtc @@ -0,0 +1,53 @@ +varnishtest "Don't retry if backend ever sent anything" + +server s1 { + rxreq + expect req.url == /1 + txresp -bodylen 1 + + rxreq + expect req.url == /2 + close + accept + + rxreq + expect req.url == /2 + txresp -bodylen 2 + + rxreq + expect req.url == /3 + send "200 " + delay .1 + close + accept + + rxreq + expect req.url == /4 + txresp -bodylen 4 +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq -url /1 + rxresp + expect resp.status == 200 + expect resp.bodylen == 1 + + # This one should get retried + txreq -url /2 + rxresp + expect resp.status == 200 + expect resp.bodylen == 2 + + # This one should not get retried + txreq -url /3 + rxresp + expect resp.status == 503 +} -run +client c1 { + txreq -url /4 + rxresp + expect resp.status == 200 + expect resp.bodylen == 4 +} -run From phk at varnish-cache.org Tue Jul 31 09:33:06 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 31 Jul 2012 11:33:06 +0200 Subject: [master] 5536bb3 Further untangle req/session state engines Message-ID: commit 5536bb3168169e1af04b4d82b1e64370e238b552 Author: Poul-Henning Kamp Date: Tue Jul 31 09:32:49 2012 +0000 Further untangle req/session state engines diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index c200bd3..64efb5d 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -93,7 +93,7 @@ static unsigned xids; DOT subgraph xcluster_wait { DOT wait [ DOT shape=box -DOT label="cnt_wait:\nwait for\ncomplete\nrequest" +DOT label="cnt_sess_wait:\nwait for\ncomplete\nrequest" DOT ] DOT herding [shape=hexagon] DOT wait -> start [label="got req",style=bold,color=green] @@ -104,7 +104,7 @@ DOT } */ static int -cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) +cnt_sess_wait(struct sess *sp, struct worker *wrk, struct req *req) { int j, tmo; struct pollfd pfd[1]; @@ -204,7 +204,6 @@ enum cnt_sess_done_ret { static enum cnt_sess_done_ret cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) { - double dh, dp, da; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -228,21 +227,8 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) sp->t_idle = W_TIM_real(wrk); - if (req->xid == 0) { + if (req->xid == 0) req->t_resp = sp->t_idle; - } else { - dp = req->t_resp - req->t_req; - da = sp->t_idle - req->t_resp; - dh = req->t_req - sp->t_open; - /* XXX: Add StatReq == StatSess */ - /* XXX: Workaround for pipe */ - if (sp->fd >= 0) { - VSLb(req->vsl, SLT_Length, "%ju", - (uintmax_t)req->req_bodybytes); - } - VSLb(req->vsl, SLT_ReqEnd, "%u %.9f %.9f %.9f %.9f %.9f", - req->xid, req->t_req, sp->t_idle, dh, dp, da); - } req->xid = 0; VSL_Flush(req->vsl, 0); @@ -351,7 +337,7 @@ CNT_Session(struct worker *wrk, struct req *req) } if (sp->sess_step == S_STP_NEWREQ) { - done = cnt_wait(sp, wrk, req); + done = cnt_sess_wait(sp, wrk, req); if (done) return; sp->sess_step = S_STP_WORKING; @@ -1593,6 +1579,19 @@ CNT_Request(struct worker *wrk, struct req *req) CHECK_OBJ_ORNULL(wrk->nobjhead, OBJHEAD_MAGIC); } if (done == 1) { + /* XXX: Workaround for pipe */ + if (req->sp->fd >= 0) { + VSLb(req->vsl, SLT_Length, "%ju", + (uintmax_t)req->req_bodybytes); + } + VSLb(req->vsl, SLT_ReqEnd, "%u %.9f %.9f %.9f %.9f %.9f", + req->xid, + req->t_req, + req->sp->t_idle, + req->sp->t_idle - req->t_resp, + req->t_resp - req->t_req, + req->sp->t_idle - req->t_resp); + /* done == 2 was charged by cache_hash.c */ SES_Charge(wrk, req); } From phk at varnish-cache.org Tue Jul 31 10:09:53 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 31 Jul 2012 12:09:53 +0200 Subject: [master] a6419c8 Fix HTC_Reinit() return type Message-ID: commit a6419c8abeceb1b7759865c23eb57dbcc46dcded Author: Poul-Henning Kamp Date: Tue Jul 31 10:09:41 2012 +0000 Fix HTC_Reinit() return type diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index dfc8f69..56c4e6b 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -881,7 +881,7 @@ enum htc_status_e { void HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *, unsigned maxbytes, unsigned maxhdr); -int HTC_Reinit(struct http_conn *htc); +enum htc_status_e HTC_Reinit(struct http_conn *htc); enum htc_status_e HTC_Rx(struct http_conn *htc); ssize_t HTC_Read(struct http_conn *htc, void *d, size_t len); enum htc_status_e HTC_Complete(struct http_conn *htc); diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 64efb5d..4132de9 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -204,7 +204,6 @@ enum cnt_sess_done_ret { static enum cnt_sess_done_ret cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) { - int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); @@ -258,8 +257,7 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) WS_Reset(wrk->aws, NULL); req->vxid = VXID_Get(&wrk->vxid_pool); - i = HTC_Reinit(req->htc); - if (i == 1) { + if (HTC_Reinit(req->htc) == HTC_COMPLETE) { req->t_req = sp->t_idle; wrk->stats.sess_pipeline++; return (SESS_DONE_RET_START); diff --git a/bin/varnishd/cache/cache_httpconn.c b/bin/varnishd/cache/cache_httpconn.c index 211e8a9..6ebb86c 100644 --- a/bin/varnishd/cache/cache_httpconn.c +++ b/bin/varnishd/cache/cache_httpconn.c @@ -75,7 +75,7 @@ HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl, * the ws somewhere, because WS_Reset only fiddles pointers. */ -int +enum htc_status_e HTC_Reinit(struct http_conn *htc) { unsigned l; From phk at varnish-cache.org Tue Jul 31 10:42:46 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 31 Jul 2012 12:42:46 +0200 Subject: [master] f81aedd More untangling of req vs. session state. Message-ID: commit f81aeddd81c12fc09c9b257963d17cca7548dda6 Author: Poul-Henning Kamp Date: Tue Jul 31 10:41:49 2012 +0000 More untangling of req vs. session state. Eliminate the t_rx timestamp, I doubt it made anything clearer for anybody. Add timestamp to SessOpen VSL record. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 56c4e6b..831c641 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -706,7 +706,6 @@ struct sess { /* Timestamps, all on TIM_real() timescale */ double t_open; /* fd accepted */ double t_idle; /* fd accepted or resp sent */ - double t_rx; #if defined(HAVE_EPOLL_CTL) struct epoll_event ev; diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 4132de9..dc7b4cc 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -118,14 +118,13 @@ cnt_sess_wait(struct sess *sp, struct worker *wrk, struct req *req) assert(req->sp == sp); - assert(!isnan(sp->t_rx)); AZ(req->vcl); AZ(req->obj); AZ(req->esi_level); assert(req->xid == 0); - req->t_req = sp->t_rx; - req->t_resp = NAN; + assert(isnan(req->t_req)); + assert(isnan(req->t_resp)); tmo = (int)(1e3 * cache_param->timeout_linger); while (1) { @@ -159,7 +158,7 @@ cnt_sess_wait(struct sess *sp, struct worker *wrk, struct req *req) when = sp->t_idle + cache_param->timeout_linger; tmo = (int)(1e3 * (when - now)); if (when < now || tmo == 0) { - sp->t_rx = NAN; + req->t_req = NAN; wrk->stats.sess_herd++; SES_ReleaseReq(req); WAIT_Enter(sp); @@ -167,7 +166,9 @@ cnt_sess_wait(struct sess *sp, struct worker *wrk, struct req *req) } } else { /* Working on it */ - when = sp->t_rx + cache_param->timeout_req; + if (isnan(req->t_req)) + req->t_req = now; + when = req->t_req + cache_param->timeout_req; tmo = (int)(1e3 * (when - now)); if (when < now || tmo == 0) { why = SC_RX_TIMEOUT; @@ -224,7 +225,6 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) req->vcl = NULL; } - sp->t_idle = W_TIM_real(wrk); if (req->xid == 0) req->t_resp = sp->t_idle; @@ -262,8 +262,6 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req) wrk->stats.sess_pipeline++; return (SESS_DONE_RET_START); } else { - sp->t_rx = sp->t_idle; - req->t_req = NAN; if (Tlen(req->htc->rxbuf)) wrk->stats.sess_readahead++; return (SESS_DONE_RET_WAIT); @@ -303,6 +301,12 @@ CNT_Session(struct worker *wrk, struct req *req) return; } + if (sp->sess_step == S_STP_NEWREQ) { + HTC_Init(req->htc, req->ws, sp->fd, req->vsl, + cache_param->http_req_size, + cache_param->http_req_hdr_len); + } + while (1) { /* * Possible entrance states diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index a521f6f..d67d5ff 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -104,7 +104,6 @@ ses_setup(struct sess *sp) sp->sockaddr.ss_family = sp->mysockaddr.ss_family = PF_UNSPEC; sp->t_open = NAN; sp->t_idle = NAN; - sp->t_rx = NAN; } /*-------------------------------------------------------------------- @@ -202,8 +201,8 @@ ses_vsl_socket(struct sess *sp, const char *lsockname) strcpy(laddr, "-"); strcpy(lport, "-"); } - VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s", - sp->addr, sp->port, lsockname, laddr, lport); + VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f", + sp->addr, sp->port, lsockname, laddr, lport, sp->t_open); } /*-------------------------------------------------------------------- @@ -232,7 +231,6 @@ SES_pool_accept_task(struct worker *wrk, void *arg) wrk->stats.s_sess++; sp->t_open = VTIM_real(); - sp->t_rx = sp->t_open; sp->t_idle = sp->t_open; sp->vxid = VXID_Get(&wrk->vxid_pool); @@ -266,10 +264,9 @@ SES_ScheduleReq(struct req *req) if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) { VSC_C_main->client_drop_late++; - sp->t_idle = VTIM_real(); AN (req->vcl); VCL_Rel(&req->vcl); - SES_Delete(sp, SC_OVERLOAD, sp->t_idle); + SES_Delete(sp, SC_OVERLOAD, NAN); return (1); } return (0); @@ -290,11 +287,9 @@ SES_Handle(struct sess *sp, double now) AN(pp->pool); sp->task.func = ses_sess_pool_task; sp->task.priv = sp; - sp->t_rx = now; if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) { VSC_C_main->client_drop_late++; - sp->t_idle = VTIM_real(); - SES_Delete(sp, SC_OVERLOAD, sp->t_idle); + SES_Delete(sp, SC_OVERLOAD, now); } } @@ -403,9 +398,8 @@ ses_GetReq(struct sess *sp) WS_Init(req->ws, "req", p, e - p); - HTC_Init(req->htc, req->ws, sp->fd, req->vsl, - cache_param->http_req_size, - cache_param->http_req_hdr_len); + req->t_req = NAN; + req->t_resp = NAN; return (req); } @@ -417,6 +411,7 @@ SES_ReleaseReq(struct req *req) struct sesspool *pp; CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + AZ(req->vcl); #define ACCT(foo) AZ(req->acct_req.foo); #include "tbl/acct_fields.h" #undef ACCT