[nginx] Upstream hash: reordered peer checks.

Maxim Dounin mdounin at mdounin.ru
Thu Oct 5 15:37:56 UTC 2017


details:   http://hg.nginx.org/nginx/rev/3b4fa572d56d
branches:  
changeset: 7124:3b4fa572d56d
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Thu Oct 05 17:43:05 2017 +0300
description:
Upstream hash: reordered peer checks.

This slightly reduces cost of selecting a peer if all or almost all peers
failed, see ticket #1030.  There should be no measureable difference with
other workloads.

diffstat:

 src/http/modules/ngx_http_upstream_hash_module.c |  14 +++++++-------
 src/stream/ngx_stream_upstream_hash_module.c     |  14 +++++++-------
 2 files changed, 14 insertions(+), 14 deletions(-)

diffs (62 lines):

diff --git a/src/http/modules/ngx_http_upstream_hash_module.c b/src/http/modules/ngx_http_upstream_hash_module.c
--- a/src/http/modules/ngx_http_upstream_hash_module.c
+++ b/src/http/modules/ngx_http_upstream_hash_module.c
@@ -543,13 +543,6 @@ ngx_http_upstream_get_chash_peer(ngx_pee
                 continue;
             }
 
-            if (peer->server.len != server->len
-                || ngx_strncmp(peer->server.data, server->data, server->len)
-                   != 0)
-            {
-                continue;
-            }
-
             if (peer->max_fails
                 && peer->fails >= peer->max_fails
                 && now - peer->checked <= peer->fail_timeout)
@@ -561,6 +554,13 @@ ngx_http_upstream_get_chash_peer(ngx_pee
                 continue;
             }
 
+            if (peer->server.len != server->len
+                || ngx_strncmp(peer->server.data, server->data, server->len)
+                   != 0)
+            {
+                continue;
+            }
+
             peer->current_weight += peer->effective_weight;
             total += peer->effective_weight;
 
diff --git a/src/stream/ngx_stream_upstream_hash_module.c b/src/stream/ngx_stream_upstream_hash_module.c
--- a/src/stream/ngx_stream_upstream_hash_module.c
+++ b/src/stream/ngx_stream_upstream_hash_module.c
@@ -544,13 +544,6 @@ ngx_stream_upstream_get_chash_peer(ngx_p
                 continue;
             }
 
-            if (peer->server.len != server->len
-                || ngx_strncmp(peer->server.data, server->data, server->len)
-                   != 0)
-            {
-                continue;
-            }
-
             if (peer->max_fails
                 && peer->fails >= peer->max_fails
                 && now - peer->checked <= peer->fail_timeout)
@@ -562,6 +555,13 @@ ngx_stream_upstream_get_chash_peer(ngx_p
                 continue;
             }
 
+            if (peer->server.len != server->len
+                || ngx_strncmp(peer->server.data, server->data, server->len)
+                   != 0)
+            {
+                continue;
+            }
+
             peer->current_weight += peer->effective_weight;
             total += peer->effective_weight;
 


More information about the nginx-devel mailing list