aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_upstream_hash_module.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2017-10-05 17:42:59 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2017-10-05 17:42:59 +0300
commita10ec2db91b448029968025d23155e9c383f522d (patch)
treeb0b3d821f3be7d46743917770fd7655ab4785ca5 /src/stream/ngx_stream_upstream_hash_module.c
parent3a2ca34548ab5d260d9d3de710ff652cf00cc0f5 (diff)
downloadnginx-a10ec2db91b448029968025d23155e9c383f522d.tar.gz
nginx-a10ec2db91b448029968025d23155e9c383f522d.zip
Upstream hash: limited number of tries in consistent case.
While this may result in non-ideal distribution of requests if nginx won't be able to select a server in a reasonable number of attempts, this still looks better than severe performance degradation observed if there is no limit and there are many points configured (ticket #1030). This is also in line with what we do for other hash balancing methods.
Diffstat (limited to 'src/stream/ngx_stream_upstream_hash_module.c')
-rw-r--r--src/stream/ngx_stream_upstream_hash_module.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/stream/ngx_stream_upstream_hash_module.c b/src/stream/ngx_stream_upstream_hash_module.c
index cb44fcdad..413537989 100644
--- a/src/stream/ngx_stream_upstream_hash_module.c
+++ b/src/stream/ngx_stream_upstream_hash_module.c
@@ -505,6 +505,11 @@ ngx_stream_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers);
+ if (hp->tries > 20 || hp->rrp.peers->single) {
+ ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
+ return hp->get_rr_peer(pc, &hp->rrp);
+ }
+
pc->connection = NULL;
now = ngx_time();
@@ -578,10 +583,9 @@ ngx_stream_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
hp->hash++;
hp->tries++;
- if (hp->tries >= points->number) {
- pc->name = hp->rrp.peers->name;
+ if (hp->tries > 20) {
ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
- return NGX_BUSY;
+ return hp->get_rr_peer(pc, &hp->rrp);
}
}