]> err.no Git - varnish/commitdiff
More caching of HTTP status
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 30 Sep 2007 20:16:28 +0000 (20:16 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 30 Sep 2007 20:16:28 +0000 (20:16 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2063 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_http.c

index cb11cf1f1c7c4f349994cdb420000e340495dc44..b48130de62aa1bed9d720830cf8291c84e0c5fd6 100644 (file)
@@ -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;
 
index 9729035cd9ab61291401c51f1768a246e2d7b655..dcc05df40727bc423e925ac2ee9bfd4fcd78dd21 100644 (file)
@@ -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);
index 1b58ae9162fac598abdd4581e916aab79f5bc393..73ef557ec22adc0f68cac01184cc539dcdb86d9a 100644 (file)
@@ -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