Welcome! Log In Create A New Profile

Advanced

improve the first selection of SWRR algorithm

陈洁 Cjhust Chen
November 04, 2020 08:00AM
Hi:
We improve the Smooth Weighted Round-Robin(SWRR) algorithm to successfully resolve the problem in the following situations.

Situation 1:
upstream backend-server {
server 1.1.1.1:8000 weight=100;
server 2.2.2.2:8000 weight=101;
server 3.3.3.3:8000 weight=100;
}

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.
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.



Situation 2:
upstream backend-server {
server 1.1.1.1:8000 weight=100;
server 2.2.2.2:8000 weight=100;
server 3.3.3.3:8000 weight=100;
}

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.
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.





# HG changeset patch
# User Jie Chen <cherrychenjie@didiglobal.com<mailto:cherrychenjie@didiglobal.com>>
# Date 1599813602 -28800
# Fri Sep 11 16:40:02 2020 +0800
# Node ID 931b0c055626657d68f886781c193ffb09245a2e
# Parent da5e3f5b16733167142b599b6af3ce9469a07d52
improve the first selection of SWRR algorithm

diff -r da5e3f5b1673 -r 931b0c055626 src/http/ngx_http_upstream_round_robin.c
--- a/src/http/ngx_http_upstream_round_robin.c Wed Sep 02 23:13:36 2020 +0300
+++ b/src/http/ngx_http_upstream_round_robin.c Fri Sep 11 16:40:02 2020 +0800
@@ -91,7 +91,7 @@
peer[n].name = server[i].addrs[j].name;
peer[n].weight = server[i].weight;
peer[n].effective_weight = server[i].weight;
- peer[n].current_weight = 0;
+ peer[n].current_weight = 0 - ngx_random() % peers->total_weight;
peer[n].max_conns = server[i].max_conns;
peer[n].max_fails = server[i].max_fails;
peer[n].fail_timeout = server[i].fail_timeout;
@@ -155,7 +155,7 @@
peer[n].name = server[i].addrs[j].name;
peer[n].weight = server[i].weight;
peer[n].effective_weight = server[i].weight;
- peer[n].current_weight = 0;
+ peer[n].current_weight = 0 - ngx_random() % peers->total_weight;
peer[n].max_conns = server[i].max_conns;
peer[n].max_fails = server[i].max_fails;
peer[n].fail_timeout = server[i].fail_timeout;





Thanks~
cherrychenjie@didiglobal.com<mailto:cherrychenjie@didiglobal.com>






_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

improve the first selection of SWRR algorithm

陈洁 Cjhust Chen 103 November 04, 2020 08:00AM

Re: improve the first selection of SWRR algorithm

Maxim Dounin 16 November 10, 2020 11:42AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 70
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready