[nginx] Upstream: included backup peers into peer.tries.

Roman Arutyunyan arut at nginx.com
Fri Sep 12 14:53:11 UTC 2014


details:   http://hg.nginx.org/nginx/rev/575175ebf4b4
branches:  
changeset: 5831:575175ebf4b4
user:      Roman Arutyunyan <arut at nginx.com>
date:      Fri Sep 12 18:50:46 2014 +0400
description:
Upstream: included backup peers into peer.tries.

Since peer.tries is never reset it can now be limited if required.

diffstat:

 src/http/modules/ngx_http_upstream_least_conn_module.c |   5 -----
 src/http/ngx_http_upstream_round_robin.c               |  13 ++++++-------
 2 files changed, 6 insertions(+), 12 deletions(-)

diffs (73 lines):

diff -r 3e5b630e0ec9 -r 575175ebf4b4 src/http/modules/ngx_http_upstream_least_conn_module.c
--- a/src/http/modules/ngx_http_upstream_least_conn_module.c	Thu Sep 11 20:09:04 2014 +0400
+++ b/src/http/modules/ngx_http_upstream_least_conn_module.c	Fri Sep 12 18:50:46 2014 +0400
@@ -299,10 +299,6 @@ ngx_http_upstream_get_least_conn_peer(ng
     lcp->rrp.tried[n] |= m;
     lcp->conns[p]++;
 
-    if (pc->tries == 1 && peers->next) {
-        pc->tries += peers->next->number;
-    }
-
     return NGX_OK;
 
 failed:
@@ -314,7 +310,6 @@ failed:
         lcp->conns += peers->number;
 
         lcp->rrp.peers = peers->next;
-        pc->tries = lcp->rrp.peers->number;
 
         n = (lcp->rrp.peers->number + (8 * sizeof(uintptr_t) - 1))
                 / (8 * sizeof(uintptr_t));
diff -r 3e5b630e0ec9 -r 575175ebf4b4 src/http/ngx_http_upstream_round_robin.c
--- a/src/http/ngx_http_upstream_round_robin.c	Thu Sep 11 20:09:04 2014 +0400
+++ b/src/http/ngx_http_upstream_round_robin.c	Fri Sep 12 18:50:46 2014 +0400
@@ -10,6 +10,10 @@
 #include <ngx_http.h>
 
 
+#define ngx_http_upstream_tries(p) ((p)->number                               \
+                                    + ((p)->next ? (p)->next->number : 0))
+
+
 static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer(
     ngx_http_upstream_rr_peer_data_t *rrp);
 
@@ -255,7 +259,7 @@ ngx_http_upstream_init_round_robin_peer(
 
     r->upstream->peer.get = ngx_http_upstream_get_round_robin_peer;
     r->upstream->peer.free = ngx_http_upstream_free_round_robin_peer;
-    r->upstream->peer.tries = rrp->peers->number;
+    r->upstream->peer.tries = ngx_http_upstream_tries(rrp->peers);
 #if (NGX_HTTP_SSL)
     r->upstream->peer.set_session =
                                ngx_http_upstream_set_round_robin_peer_session;
@@ -374,7 +378,7 @@ ngx_http_upstream_create_round_robin_pee
 
     r->upstream->peer.get = ngx_http_upstream_get_round_robin_peer;
     r->upstream->peer.free = ngx_http_upstream_free_round_robin_peer;
-    r->upstream->peer.tries = rrp->peers->number;
+    r->upstream->peer.tries = ngx_http_upstream_tries(rrp->peers);
 #if (NGX_HTTP_SSL)
     r->upstream->peer.set_session = ngx_http_upstream_empty_set_session;
     r->upstream->peer.save_session = ngx_http_upstream_empty_save_session;
@@ -432,10 +436,6 @@ ngx_http_upstream_get_round_robin_peer(n
 
     /* ngx_unlock_mutex(peers->mutex); */
 
-    if (pc->tries == 1 && peers->next) {
-        pc->tries += peers->next->number;
-    }
-
     return NGX_OK;
 
 failed:
@@ -447,7 +447,6 @@ failed:
         ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, "backup servers");
 
         rrp->peers = peers->next;
-        pc->tries = rrp->peers->number;
 
         n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1))
                 / (8 * sizeof(uintptr_t));



More information about the nginx-devel mailing list