Mercurial > hg > nginx
comparison src/stream/ngx_stream_upstream_hash_module.c @ 7123:6c52b24fcf8e
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 05 Oct 2017 17:42:59 +0300 |
parents | 29bf0dbc0a77 |
children | 3b4fa572d56d |
comparison
equal
deleted
inserted
replaced
7122:935b1902a7dd | 7123:6c52b24fcf8e |
---|---|
503 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pc->log, 0, | 503 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, pc->log, 0, |
504 "get consistent hash peer, try: %ui", pc->tries); | 504 "get consistent hash peer, try: %ui", pc->tries); |
505 | 505 |
506 ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers); | 506 ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers); |
507 | 507 |
508 if (hp->tries > 20 || hp->rrp.peers->single) { | |
509 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | |
510 return hp->get_rr_peer(pc, &hp->rrp); | |
511 } | |
512 | |
508 pc->connection = NULL; | 513 pc->connection = NULL; |
509 | 514 |
510 now = ngx_time(); | 515 now = ngx_time(); |
511 hcf = hp->conf; | 516 hcf = hp->conf; |
512 | 517 |
576 } | 581 } |
577 | 582 |
578 hp->hash++; | 583 hp->hash++; |
579 hp->tries++; | 584 hp->tries++; |
580 | 585 |
581 if (hp->tries >= points->number) { | 586 if (hp->tries > 20) { |
582 pc->name = hp->rrp.peers->name; | |
583 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); | 587 ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers); |
584 return NGX_BUSY; | 588 return hp->get_rr_peer(pc, &hp->rrp); |
585 } | 589 } |
586 } | 590 } |
587 | 591 |
588 hp->rrp.current = best; | 592 hp->rrp.current = best; |
589 | 593 |