[upstream] consistent hash support backup?

Ruslan Ermilov ru at nginx.com
Wed Nov 8 13:11:44 UTC 2017


On Mon, Nov 06, 2017 at 09:35:14PM +0800, 洪志道 wrote:
>    Hi!
>    We know that consistent hash upstream improve its selection in the latest
>    version.
> 
>  -        if (hp->tries >= points->number) {
>  -            pc->name = hp->rrp.peers->name;
>  +        if (hp->tries > 20) {
>               ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
>  -            return NGX_BUSY;
>  +            return hp->get_rr_peer(pc, &hp->rrp);
> 
>  Does it mean that "backup" option is allowed in the module?

It just means that if, after 20 tries, we weren't able to select
a peer using the hash algorithm, then we'll continue a selection
process using the round-robin algorithm.  This is also consistent
with the ip_hash module.

>                     |NGX_HTTP_UPSTREAM_MAX_CONNS
>                     |NGX_HTTP_UPSTREAM_MAX_FAILS
>                     |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
>  +                  |NGX_HTTP_UPSTREAM_BACKUP
>                     |NGX_HTTP_UPSTREAM_DOWN;

We do not support backup servers with ip_hash and hash balancers,
though there's currently a bypass that allows to have backup
servers in configurations with hash balancers.  But these backup
servers will be used only when falling back to round-robin, which
is unlikely.

>  I wonder how to archive the effect of "backup" in hash like round robin,
>  even if we don't want to use error_page.

I'm not sure what did you mean here.


More information about the nginx-devel mailing list