<div dir="ltr"><div>Hi Francis,</div><div><br></div>Thanks for confirming that there is no document, and any results observed through testing or reviewing code will not be guaranteed. I guess it is purposely undocumented so that people won't rely on one behavior and we are free to change.<div><br></div><div>Regards,</div><div>Frank</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 13, 2017 at 4:49 PM, Francis Daly <span dir="ltr"><<a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Apr 12, 2017 at 02:50:08PM -0700, Frank Liu wrote:<br>
<br>
Hi there,<br>
<span class=""><br>
> How does nginx balances traffic to upstream with different weight? If I<br>
> have 3 servers in upstream, with weight 1, 2, 4, assuming all are healthy,<br>
> will nginx send traffic to server 1, 2, 3, 2, 3, 3, 3 or 1, 2, 2, 3, 3, 3,<br>
> 3?<br>
<br>
</span>If you want to know what your current nginx version does, it should not<br>
be too difficult to test:<br>
<br>
One nginx.conf. One http section. One upstream{} listing multiple<br>
ip:ports. One server{} which proxy_pass:es to that upstream. Multiple<br>
server{}s, each of which listens on one ip:port, writes to a different<br>
access_log, and does something like "return 200 ok;".<br>
<br>
Then for increasing numbers X, "GET /X" on the main server. Look at<br>
the individual access log files to see which server handled /1, which<br>
handled /2, etc. By the time you get to 700, you'll either see that<br>
there is a reliably repeating pattern, or you'll see that it is probably<br>
randomish.<br>
<br>
<br>
If you actually care about what pattern is used; or if you want to<br>
guarantee that the same pattern will be used in future nginx versions;<br>
then get your preferred code written and use that instead of whatever<br>
nginx uses.<br>
<br>
<br>
If you want to know what guarantee there is that the behaviour will not<br>
change in the future: I'd say "none", except that there is a good chance<br>
that what is written in the documentation will be honoured. Paraphrasing<br>
that, for the above case: for 7 requests, 1 will go to the first server;<br>
2 to the second; and 4 to the third.<br>
<span class=""><br>
> If I have two servers with both weight 50, will nginx will 50 requests<br>
> to server 1, and then 50 to server 2, or will it calculate the ration to be<br>
> 1:1 and send one after another?<br>
<br>
</span>Same answer: it does not seem to difficult to test, if you don't want<br>
to read the available source.<br>
<br>
Good luck with it!<br>
<span class="HOEnZb"><font color="#888888"><br>
f<br>
--<br>
Francis Daly <a href="mailto:francis@daoine.org">francis@daoine.org</a><br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx</a><br>
</div></div></blockquote></div><br></div>