From cc3ddf7061d56167c6e64634972e19022a946a7f Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 7 Mar 2008 11:36:52 +0000 Subject: [PATCH] Add diagnostic features to keep track of object workspace usage. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2560 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 4 +++- varnish-cache/bin/varnishd/cache_center.c | 8 ++++---- varnish-cache/bin/varnishd/cache_hash.c | 15 ++++++++++++++- varnish-cache/bin/varnishd/cache_ws.c | 12 +++++++++++- varnish-cache/bin/varnishd/mgt_param.c | 1 + varnish-cache/include/stat_field.h | 1 + 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index b4352a1a..732444ed 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -107,6 +107,7 @@ struct ws { char *f; /* (F)ree pointer */ char *r; /* (R)eserved length */ char *e; /* (E)nd of buffer */ + int overflow; /* workspace overflowed */ }; /*-------------------------------------------------------------------- @@ -444,7 +445,7 @@ void HSH_Prealloc(struct sess *sp); int HSH_Compare(const struct sess *sp, const struct objhead *o); void HSH_Copy(const struct sess *sp, const struct objhead *o); struct object *HSH_Lookup(struct sess *sp); -void HSH_Unbusy(struct object *o); +void HSH_Unbusy(struct sess *sp); void HSH_Ref(struct object *o); void HSH_Deref(struct object *o); void HSH_Init(void); @@ -580,6 +581,7 @@ void WS_Reset(struct ws *ws, char *p); char *WS_Alloc(struct ws *ws, unsigned bytes); char *WS_Dup(struct ws *ws, const char *); char *WS_Snapshot(struct ws *ws); +unsigned WS_Used(struct ws *ws); /* rfc2616.c */ int RFC2616_cache_policy(const struct sess *sp, const struct http *hp); diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 91a202e0..b6ee8028 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -352,7 +352,7 @@ cnt_fetch(struct sess *sp) case VCL_RET_RESTART: sp->obj->ttl = 0; sp->obj->cacheable = 0; - HSH_Unbusy(sp->obj); + HSH_Unbusy(sp); HSH_Deref(sp->obj); sp->obj = NULL; if (sp->handling == VCL_RET_ERROR) @@ -375,7 +375,7 @@ cnt_fetch(struct sess *sp) if (sp->obj->objhead != NULL) { VRY_Create(sp); EXP_Insert(sp->obj, sp->wrk->used); - HSH_Unbusy(sp->obj); + HSH_Unbusy(sp); } sp->wrk->acct.fetch++; sp->step = STP_DELIVER; @@ -626,7 +626,7 @@ cnt_miss(struct sess *sp) VCL_miss_method(sp); if (sp->handling == VCL_RET_ERROR) { sp->obj->cacheable = 0; - HSH_Unbusy(sp->obj); + HSH_Unbusy(sp); HSH_Deref(sp->obj); sp->obj = NULL; VBE_free_bereq(sp->bereq); @@ -636,7 +636,7 @@ cnt_miss(struct sess *sp) } if (sp->handling == VCL_RET_PASS) { sp->obj->cacheable = 0; - HSH_Unbusy(sp->obj); + HSH_Unbusy(sp); HSH_Deref(sp->obj); sp->obj = NULL; sp->step = STP_PASS; diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 5c628f5d..59022c02 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -285,14 +285,23 @@ hsh_rush(struct objhead *oh) } void -HSH_Unbusy(struct object *o) +HSH_Unbusy(struct sess *sp) { + struct object *o; struct objhead *oh; struct object *parent; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + o = sp->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); assert(o->busy); assert(o->refcnt > 0); + if (o->ws_o->overflow) + VSL_stats->n_objoverflow++; + if (params->diag_bitmap & 0x40) + WSP(sp, SLT_Debug, + "Object workspace used %u", WS_Used(o->ws_o)); + oh = o->objhead; if (oh != NULL) { CHECK_OBJ(oh, OBJHEAD_MAGIC); @@ -356,6 +365,10 @@ HSH_Deref(struct object *o) if (r != 0) return; + if (params->diag_bitmap & 0x40) + VSL(SLT_Debug, 0, + "Object workspace max used %u", WS_Used(o->ws_o)); + if (o->vary != NULL) free(o->vary); diff --git a/varnish-cache/bin/varnishd/cache_ws.c b/varnish-cache/bin/varnishd/cache_ws.c index e40e1e07..a5b0d793 100644 --- a/varnish-cache/bin/varnishd/cache_ws.c +++ b/varnish-cache/bin/varnishd/cache_ws.c @@ -111,8 +111,10 @@ WS_Alloc(struct ws *ws, unsigned bytes) WS_Assert(ws); assert(ws->r == NULL); - if (ws->f + bytes > ws->e) + if (ws->f + bytes > ws->e) { + ws->overflow++; return(NULL); + } r = ws->f; ws->f += bytes; WS_DEBUG("WS_Alloc(%p, %u) = %p", ws, bytes, r); @@ -133,6 +135,14 @@ WS_Dup(struct ws *ws, const char *s) return (p); } +unsigned +WS_Used(struct ws *ws) +{ + + WS_Assert(ws); + return(ws->f - ws->s); +} + char * WS_Snapshot(struct ws *ws) { diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index c394ea9f..0ab4ea03 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -652,6 +652,7 @@ static const struct parspec parspec[] = { " 0x00000008 - mutex logging.\n" " 0x00000010 - mutex contests.\n" " 0x00000020 - waiting list.\n" + " 0x00000040 - object workspace.\n" "Use 0x notation and do the bitor in your head :-)\n", 0, "0", "bitmap" }, diff --git a/varnish-cache/include/stat_field.h b/varnish-cache/include/stat_field.h index c3910eba..95fc980e 100644 --- a/varnish-cache/include/stat_field.h +++ b/varnish-cache/include/stat_field.h @@ -72,6 +72,7 @@ MAC_STAT(losthdr, uint64_t, 'a', "HTTP header overflows") MAC_STAT(n_objsendfile, uint64_t, 'a', "Objects sent with sendfile") MAC_STAT(n_objwrite, uint64_t, 'a', "Objects sent with write") +MAC_STAT(n_objoverflow, uint64_t, 'a', "Objects overflowing workspace") MAC_STAT(s_sess, uint64_t, 'a', "Total Sessions") MAC_STAT(s_req, uint64_t, 'a', "Total Requests") -- 2.39.5