<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div class="">
<div class="">Hi:</div>
<div class="">     We improve the Smooth Weighted Round-Robin(SWRR) algorithm to successfully resolve the problem in the following situations.</div>
<div class=""><br class="">
</div>
<div class=""><span style="font-size: 14px;" class="">Situation 1:</span></div>
<div class="">upstream backend-server {</div>
<div class="">     server 1.1.1.1:8000  weight=100;</div>
<div class="">     server 2.2.2.2:8000 <b class=""> <font color="#ff2600" class="">weight=101;</font></b></div>
<div class="">     server 3.3.3.3:8000  weight=100;</div>
<div class="">}</div>
<div class=""><br class="">
</div>
<div class="">1. When each machine in the cluster mode executes "-s reload" at the same time , the first selection of each machine is the machine 2.2.2.2:8000 having higher weight , which will lead to 300%+ increase of 2.2.2.2:8000 traffic.</div>
<div class="">2. More and more companies are implementing service discovery based on nginx. Adding or removing machine will also lead to 300%+ increase of 2.2.2.2:8000 traffic.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><span style="font-size: 14px;" class="">Situation 2:</span></div>
<div class="">upstream backend-server {</div>
<div class="">     server 1.1.1.1:8000  weight=100;</div>
<div class="">     server 2.2.2.2:8000  weight=100;</div>
<div class="">     server 3.3.3.3:8000  weight=100;</div>
<div class="">}</div>
<div class=""><br class="">
</div>
<div class="">1. When each machine in the cluster mode executes "-s reload" at the same time , the first selection of each machine is the first machine 1.1.1.1:8000, which will lead to 300%+ increase of 1.1.1.1:8000 traffic.</div>
<div class="">2. More and more companies are implementing service discovery based on nginx. Adding or removing machine will also lead to 300%+ increase of 1.1.1.1:8000 traffic.</div>
<div class=""></div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div class=""># HG changeset patch</div>
<div class=""># User Jie Chen <<a href="mailto:cherrychenjie@didiglobal.com" class="">cherrychenjie@didiglobal.com</a>></div>
<div class=""># Date 1599813602 -28800</div>
<div class="">#      Fri Sep 11 16:40:02 2020 +0800</div>
<div class=""># Node ID 931b0c055626657d68f886781c193ffb09245a2e</div>
<div class=""># Parent  da5e3f5b16733167142b599b6af3ce9469a07d52</div>
<div class="">improve the first selection of SWRR algorithm</div>
<div class=""><br class="">
</div>
<div class="">diff -r da5e3f5b1673 -r 931b0c055626 src/http/ngx_http_upstream_round_robin.c</div>
<div class="">--- a/src/http/ngx_http_upstream_round_robin.c  Wed Sep 02 23:13:36 2020 +0300</div>
<div class="">+++ b/src/http/ngx_http_upstream_round_robin.c  Fri Sep 11 16:40:02 2020 +0800</div>
<div class="">@@ -91,7 +91,7 @@</div>
<div class="">                 peer[n].name = server[i].addrs[j].name;</div>
<div class="">                 peer[n].weight = server[i].weight;</div>
<div class="">                 peer[n].effective_weight = server[i].weight;</div>
<div class="">-                peer[n].current_weight = 0;</div>
<div class="">+                peer[n].current_weight = 0 - ngx_random() % peers->total_weight;</div>
<div class="">                 peer[n].max_conns = server[i].max_conns;</div>
<div class="">                 peer[n].max_fails = server[i].max_fails;</div>
<div class="">                 peer[n].fail_timeout = server[i].fail_timeout;</div>
<div class="">@@ -155,7 +155,7 @@</div>
<div class="">                 peer[n].name = server[i].addrs[j].name;</div>
<div class="">                 peer[n].weight = server[i].weight;</div>
<div class="">                 peer[n].effective_weight = server[i].weight;</div>
<div class="">-                peer[n].current_weight = 0;</div>
<div class="">+                peer[n].current_weight = 0 - ngx_random() % peers->total_weight;</div>
<div class="">                 peer[n].max_conns = server[i].max_conns;</div>
<div class="">                 peer[n].max_fails = server[i].max_fails;</div>
<div class="">                 peer[n].fail_timeout = server[i].fail_timeout;</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Thanks~</div>
<div class=""><a href="mailto:cherrychenjie@didiglobal.com" class="">cherrychenjie@didiglobal.com</a></div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>