Mercurial > hg > nginx
diff src/http/modules/ngx_http_upstream_ip_hash_module.c @ 6121:b6047abf5f30
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.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 21 Apr 2015 19:09:04 +0300 |
parents | 55dc5f7eb921 |
children | f01ab2dbcfdc |
line wrap: on
line diff
--- 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_p 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; + w = hash % iphp->rrp.peers->total_weight; + peer = iphp->rrp.peers->peer; + p = 0; - for (peer = iphp->rrp.peers->peer, i = 0; - peer; - peer = peer->next, i++) - { - w -= peer->weight; - if (w < 0) { - break; - } - } - - p = i; + while (w >= peer->weight) { + w -= peer->weight; + peer = peer->next; + p++; } n = p / (8 * sizeof(uintptr_t));