From a2b72ef101c8949826250bf46e5f2f6defa5b153 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 30 Sep 2007 20:16:28 +0000 Subject: [PATCH] More caching of HTTP status git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2063 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_center.c | 18 ------------------ varnish-cache/bin/varnishd/cache_fetch.c | 9 +++++---- varnish-cache/bin/varnishd/cache_http.c | 5 ++--- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index cb11cf1f..b48130de 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -300,24 +300,6 @@ cnt_fetch(struct sess *sp) i = Fetch(sp); CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); - /* Experimental. Set time for last check of backend health. - * If the backend replied with 200, it is obviously up and running, - * increase health parameter. If we got a 504 back, it would imply - * that the backend is not reachable. Decrease health parameter. - */ - sp->backend->last_check = TIM_mono(); - sp->backend->minute_limit = 1; - if (!i){ - if (http_GetStatus(sp->bereq->http) == 200) { - if (sp->backend->health < 10000) - sp->backend->health++; - } else if(http_GetStatus(sp->bereq->http) == 504) { - if (sp->backend->health > -10000) - sp->backend->health--; - } - } - - VBE_free_bereq(sp->bereq); sp->bereq = NULL; diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 9729035c..dcc05df4 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -282,6 +282,7 @@ Fetch(struct sess *sp) WRK_Reset(w, &vc->fd); http_Write(w, hp, 0); if (WRK_Flush(w)) { + VBE_UpdateHealth(sp, vc, -1); VBE_ClosedFd(sp->wrk, vc); /* XXX: other cleanup ? */ return (1); @@ -296,6 +297,7 @@ Fetch(struct sess *sp) while (i == 0); if (http_DissectResponse(sp->wrk, htc, hp)) { + VBE_UpdateHealth(sp, vc, -2); VBE_ClosedFd(sp->wrk, vc); /* XXX: other cleanup ? */ return (1); @@ -335,6 +337,7 @@ Fetch(struct sess *sp) } else if (http_GetHdr(hp, H_Transfer_Encoding, &b)) { /* XXX: AUGH! */ WSL(sp->wrk, SLT_Debug, vc->fd, "Invalid Transfer-Encoding"); + VBE_UpdateHealth(sp, vc, -3); VBE_ClosedFd(sp->wrk, vc); return (-1); } else if (strcmp(http_GetProto(hp), "HTTP/1.1")) { @@ -355,6 +358,7 @@ Fetch(struct sess *sp) VTAILQ_REMOVE(&sp->obj->store, st, list); STV_free(st); } + VBE_UpdateHealth(sp, vc, -4); VBE_ClosedFd(sp->wrk, vc); return (-1); } @@ -376,10 +380,7 @@ Fetch(struct sess *sp) if (http_GetHdr(hp, H_Connection, &b) && !strcasecmp(b, "close")) cls = 1; - if (http_GetStatus(sp->bereq->http) == 200) - VBE_UpdateHealth(sp, vc, 1); - else if(http_GetStatus(sp->bereq->http) == 504) - VBE_UpdateHealth(sp, vc, -1); + VBE_UpdateHealth(sp, vc, http_GetStatus(sp->bereq->http)); if (cls) VBE_ClosedFd(sp->wrk, vc); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 1b58ae91..73ef557e 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -327,9 +327,6 @@ http_GetStatus(const struct http *hp) { Tcheck(hp->hd[HTTP_HDR_STATUS]); - if (hp->status == 0) - hp->status = strtoul(hp->hd[HTTP_HDR_STATUS].b, - NULL /* XXX */, 10)); return (hp->status); } @@ -506,6 +503,7 @@ http_DissectResponse(struct worker *w, const struct http_conn *htc, struct http if (i != 0 || memcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.", 7)) WSLR(w, SLT_HttpGarbage, htc->fd, htc->rxbuf); + hp->status = strtoul(hp->hd[HTTP_HDR_STATUS].b, NULL /* XXX */, 10); return (i); } @@ -738,6 +736,7 @@ http_PutStatus(struct worker *w, int fd, struct http *to, int status) assert(status >= 0 && status <= 999); sprintf(stat, "%d", status); http_PutField(w, fd, to, HTTP_HDR_STATUS, stat); + to->status = status; } void -- 2.39.5