recently,i begain to use nginx.1.1.4 to test upstream keepalived,but i found it olny i must set the keepalive_timeout  X (X>0),the upstream keepalive can work , isn't it?<div><div class="gmail_quote">2011/9/27 Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"># HG changeset patch<br>
# User Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>><br>
# Date 1317126090 -14400<br>
# Node ID a0fc6910248f8f92ff8b7cc1465ba3fd8cd8c52d<br>
# Parent  a0228f0e9fe2ad166324a80bc915ad8ec1050dcc<br>
Better recheck of dead upstream servers.<br>
<br>
Previously nginx used to mark backend again as live as soon as fail_timeout<br>
passes (10s by default) since last failure.  On the other hand, detecting<br>
dead backend takes up to 60s (proxy_connect_timeout) in typical situation<br>
"backend is down and doesn't respond to any packets".  This resulted in<br>
suboptimal behaviour in the above situation (up to 23% of requests were<br>
directed to dead backend with default settings).<br>
<br>
More detailed description of the problem may be found here (in Russian):<br>
<a href="http://mailman.nginx.org/pipermail/nginx-ru/2011-August/042172.html" target="_blank">http://mailman.nginx.org/pipermail/nginx-ru/2011-August/042172.html</a><br>
<br>
Fix is to only allow one request after fail_timeout passes, and<br>
mark backend as "live" only if this request succeeds.<br>
<br>
Note that with new code backend will not be marked "live" unless "check"<br>
request is completed, and this may take a while in some specific workloads<br>
(e.g. streaming).  This is believed to be acceptable.<br>
<br>
diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c<br>
--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c<br>
+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c<br>
@@ -185,8 +185,8 @@ ngx_http_upstream_get_ip_hash_peer(ngx_p<br>
                     break;<br>
                 }<br>
<br>
-                if (now - peer->accessed > peer->fail_timeout) {<br>
-                    peer->fails = 0;<br>
+                if (now - peer->checked > peer->fail_timeout) {<br>
+                    peer->checked = now;<br>
                     break;<br>
                 }<br>
             }<br>
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c<br>
--- a/src/http/ngx_http_upstream_round_robin.c<br>
+++ b/src/http/ngx_http_upstream_round_robin.c<br>
@@ -443,8 +443,8 @@ ngx_http_upstream_get_round_robin_peer(n<br>
                             break;<br>
                         }<br>
<br>
-                        if (now - peer->accessed > peer->fail_timeout) {<br>
-                            peer->fails = 0;<br>
+                        if (now - peer->checked > peer->fail_timeout) {<br>
+                            peer->checked = now;<br>
                             break;<br>
                         }<br>
<br>
@@ -491,8 +491,8 @@ ngx_http_upstream_get_round_robin_peer(n<br>
                             break;<br>
                         }<br>
<br>
-                        if (now - peer->accessed > peer->fail_timeout) {<br>
-                            peer->fails = 0;<br>
+                        if (now - peer->checked > peer->fail_timeout) {<br>
+                            peer->checked = now;<br>
                             break;<br>
                         }<br>
<br>
@@ -663,15 +663,16 @@ ngx_http_upstream_free_round_robin_peer(<br>
         return;<br>
     }<br>
<br>
+    peer = &rrp->peers->peer[rrp->current];<br>
+<br>
     if (state & NGX_PEER_FAILED) {<br>
         now = ngx_time();<br>
<br>
-        peer = &rrp->peers->peer[rrp->current];<br>
-<br>
         /* ngx_lock_mutex(rrp->peers->mutex); */<br>
<br>
         peer->fails++;<br>
         peer->accessed = now;<br>
+        peer->checked = now;<br>
<br>
         if (peer->max_fails) {<br>
             peer->current_weight -= peer->weight / peer->max_fails;<br>
@@ -686,6 +687,14 @@ ngx_http_upstream_free_round_robin_peer(<br>
         }<br>
<br>
         /* ngx_unlock_mutex(rrp->peers->mutex); */<br>
+<br>
+    } else {<br>
+<br>
+        /* mark peer live if check passed */<br>
+<br>
+        if (peer->accessed < peer->checked) {<br>
+            peer->fails = 0;<br>
+        }<br>
     }<br>
<br>
     rrp->current++;<br>
diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h<br>
--- a/src/http/ngx_http_upstream_round_robin.h<br>
+++ b/src/http/ngx_http_upstream_round_robin.h<br>
@@ -23,6 +23,7 @@ typedef struct {<br>
<br>
     ngx_uint_t                      fails;<br>
     time_t                          accessed;<br>
+    time_t                          checked;<br>
<br>
     ngx_uint_t                      max_fails;<br>
     time_t                          fail_timeout;<br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br></div>