mirror of
https://github.com/nginx/nginx.git
synced 2024-12-19 21:53:31 -06:00
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.
This commit is contained in:
parent
b6517ea696
commit
673941f81d
@ -170,7 +170,7 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
|||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
ngx_int_t w;
|
ngx_int_t w;
|
||||||
uintptr_t m;
|
uintptr_t m;
|
||||||
ngx_uint_t i, n, p;
|
ngx_uint_t n, p;
|
||||||
ngx_http_upstream_rr_peer_t *peer;
|
ngx_http_upstream_rr_peer_t *peer;
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
||||||
@ -211,28 +211,14 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
|||||||
hp->hash += hash;
|
hp->hash += hash;
|
||||||
hp->rehash++;
|
hp->rehash++;
|
||||||
|
|
||||||
if (!hp->rrp.peers->weighted) {
|
w = hp->hash % hp->rrp.peers->total_weight;
|
||||||
p = hp->hash % hp->rrp.peers->number;
|
peer = hp->rrp.peers->peer;
|
||||||
|
p = 0;
|
||||||
|
|
||||||
peer = hp->rrp.peers->peer;
|
while (w >= peer->weight) {
|
||||||
for (i = 0; i < p; i++) {
|
w -= peer->weight;
|
||||||
peer = peer->next;
|
peer = peer->next;
|
||||||
}
|
p++;
|
||||||
|
|
||||||
} else {
|
|
||||||
w = hp->hash % hp->rrp.peers->total_weight;
|
|
||||||
|
|
||||||
for (peer = hp->rrp.peers->peer, i = 0;
|
|
||||||
peer;
|
|
||||||
peer = peer->next, i++)
|
|
||||||
{
|
|
||||||
w -= peer->weight;
|
|
||||||
if (w < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = p / (8 * sizeof(uintptr_t));
|
n = p / (8 * sizeof(uintptr_t));
|
||||||
|
@ -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;
|
hash = (hash * 113 + iphp->addr[i]) % 6271;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iphp->rrp.peers->weighted) {
|
w = hash % iphp->rrp.peers->total_weight;
|
||||||
p = hash % iphp->rrp.peers->number;
|
peer = iphp->rrp.peers->peer;
|
||||||
|
p = 0;
|
||||||
|
|
||||||
peer = iphp->rrp.peers->peer;
|
while (w >= peer->weight) {
|
||||||
for (i = 0; i < p; i++) {
|
w -= peer->weight;
|
||||||
peer = peer->next;
|
peer = peer->next;
|
||||||
}
|
p++;
|
||||||
|
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = p / (8 * sizeof(uintptr_t));
|
n = p / (8 * sizeof(uintptr_t));
|
||||||
|
@ -164,7 +164,7 @@ ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
|||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
ngx_int_t w;
|
ngx_int_t w;
|
||||||
uintptr_t m;
|
uintptr_t m;
|
||||||
ngx_uint_t i, n, p;
|
ngx_uint_t n, p;
|
||||||
ngx_stream_upstream_rr_peer_t *peer;
|
ngx_stream_upstream_rr_peer_t *peer;
|
||||||
|
|
||||||
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pc->log, 0,
|
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pc->log, 0,
|
||||||
@ -204,28 +204,14 @@ ngx_stream_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
|||||||
hp->hash += hash;
|
hp->hash += hash;
|
||||||
hp->rehash++;
|
hp->rehash++;
|
||||||
|
|
||||||
if (!hp->rrp.peers->weighted) {
|
w = hp->hash % hp->rrp.peers->total_weight;
|
||||||
p = hp->hash % hp->rrp.peers->number;
|
peer = hp->rrp.peers->peer;
|
||||||
|
p = 0;
|
||||||
|
|
||||||
peer = hp->rrp.peers->peer;
|
while (w >= peer->weight) {
|
||||||
for (i = 0; i < p; i++) {
|
w -= peer->weight;
|
||||||
peer = peer->next;
|
peer = peer->next;
|
||||||
}
|
p++;
|
||||||
|
|
||||||
} else {
|
|
||||||
w = hp->hash % hp->rrp.peers->total_weight;
|
|
||||||
|
|
||||||
for (peer = hp->rrp.peers->peer, i = 0;
|
|
||||||
peer;
|
|
||||||
peer = peer->next, i++)
|
|
||||||
{
|
|
||||||
w -= peer->weight;
|
|
||||||
if (w < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = p / (8 * sizeof(uintptr_t));
|
n = p / (8 * sizeof(uintptr_t));
|
||||||
|
Loading…
Reference in New Issue
Block a user