diff options
author | Ruslan Ermilov <ru@nginx.com> | 2015-04-21 19:09:04 +0300 |
---|---|---|
committer | Ruslan Ermilov <ru@nginx.com> | 2015-04-21 19:09:04 +0300 |
commit | 673941f81dfc724f9d98d1d1c0e50c8e08e3e327 (patch) | |
tree | 4932af1fad9ae8d72af3023d4b0e7baf5d46d704 /src/http/modules/ngx_http_upstream_ip_hash_module.c | |
parent | b6517ea696e1cda71844c8d3178ad9835ec963b9 (diff) | |
download | nginx-673941f81dfc724f9d98d1d1c0e50c8e08e3e327.tar.gz nginx-673941f81dfc724f9d98d1d1c0e50c8e08e3e327.zip |
Upstream: simplified ip_hash and hash peer selection code.
Now that peers are stored as a list, the weighted and unweighted
cases became nearly identical.
Diffstat (limited to 'src/http/modules/ngx_http_upstream_ip_hash_module.c')
-rw-r--r-- | src/http/modules/ngx_http_upstream_ip_hash_module.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c index d1d71e478..401b58e5c 100644 --- a/src/http/modules/ngx_http_upstream_ip_hash_module.c +++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c @@ -181,28 +181,14 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data) hash = (hash * 113 + iphp->addr[i]) % 6271; } - if (!iphp->rrp.peers->weighted) { - p = hash % iphp->rrp.peers->number; - - peer = iphp->rrp.peers->peer; - for (i = 0; i < p; i++) { - peer = peer->next; - } - - } else { - w = hash % iphp->rrp.peers->total_weight; - - for (peer = iphp->rrp.peers->peer, i = 0; - peer; - peer = peer->next, i++) - { - w -= peer->weight; - if (w < 0) { - break; - } - } - - p = i; + w = hash % iphp->rrp.peers->total_weight; + peer = iphp->rrp.peers->peer; + p = 0; + + while (w >= peer->weight) { + w -= peer->weight; + peer = peer->next; + p++; } n = p / (8 * sizeof(uintptr_t)); |