<div dir="ltr"><div>Thanks for the explanation.</div><div><br></div><div>I don't think changing the current implementation would be a good idea, but what do you think of adding another option in addition to "consistent"?<br></div><div>It could use the consistent hashing algorithm with peer IP addresses instead of hostnames, as you suggested.</div><div>Not sure what the nginx policy is for that sort of change.</div><div><br></div><div>If that's not possible, do you think we could at least add a line to the documentation about this edge case?</div><div><br></div><div>Thanks<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 11 Feb 2021 at 04:22, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello!<br>
<br>
On Wed, Feb 10, 2021 at 07:03:30PM +0200, Ari Croock wrote:<br>
<br>
> That makes sense to me, except for the fact that "hash" (without<br>
> "consistent") doesn't seem to be doing round-robin load balancing.<br>
> <br>
> Is there a reason that regular "hash" keeps returning a consistent IP? I<br>
> could understand if both directives resulted in the behaviour you<br>
> described, but it seems strange that only one would.<br>
<br>
That's because the algorithms used are quite different.<br>
<br>
Simple hashing algorithm doesn't care about being consistent, and <br>
uses the Nth peer, where N is calculated as a hash modulo <br>
total number of peers. This works good as long as the list of <br>
servers is not changed. If the list is changed, however, new hashing <br>
will result in completely different peer being used for requests <br>
with the same hash key. Note that "the list is changed" also <br>
implies changes in number or order of IP addresses if you use <br>
names in the configuration.<br>
<br>
Consistent hashing works differently: instead, it tries to <br>
preserve mapping from hash to a particular upstream server. To do <br>
so, it relies on names used in the configuration, so changes in <br>
the configuration, such as order of servers, or even changes of IP <br>
addresses used by particular servers, do not affect distribution <br>
of the requests between servers. As a result, if a name in the <br>
configuration maps to more than one IP address, these addresses <br>
are equal to the algorithm, since they use the same name.<br>
<br>
It should be possible to implement consistent hashing differently, <br>
for example, using IP addresses of the particular peers instead of <br>
names from the configuration. This approach will probably match <br>
what you are trying to do somewhat better. This is not how it is <br>
currently implemented in nginx though.<br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/" rel="noreferrer" target="_blank">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="color:rgb(102,102,102);font-family:Arial,sans-serif">Ari Croock | Isazi | Software Engineer | BSc (Eng) - Electrical</span></div><div><p style="margin:0px"><font color="#666666"><span style="font-family:Wingdings" lang="EN-ZA"><span style="font-family:Arial,sans-serif">38 Homestead Road, Rivonia, Johannesburg, South Africa, 2128 |</span>(</span><span style="font-family:"Tms Rmn",serif" lang="EN-ZA">:</span><span style="font-family:Arial,sans-serif" lang="EN-ZA"> +27 11 027 6996 </span></font></p><p style="margin:0px"><span style="font-family:Arial,sans-serif" lang="EN-ZA"><font color="#666666"><span style="font-family:Wingdings" lang="EN-ZA">*</span><span style="font-family:"Tms Rmn",serif" lang="EN-ZA">: </span><span style="font-family:Arial,Helvetica,sans-serif" lang="EN-ZA"><font face="Arial, sans-serif"><a href="mailto:acroock@isazi.ai" target="_blank">acroock@isazi.ai</a> | </font></span><a href="http://www.isazi.ai/" style="font-family:Arial" target="_blank">www.isazi.ai</a><span style="font-family:Arial"> </span></font></span></p></div><div><div><span style="color:rgb(102,102,102);font-family:Arial,sans-serif"><img src="https://drive.google.com/uc?id=1Hqvt6vw0LDuLmQErdARvBc9H_oxfgZzV&export=download" width="200" height="53"></span></div></div></div></div>