--- alias: operation-guide-roundrobin description: "Weighted round-robin scheduling prioritizes servers based on assigned processing capacities" --- # Weighted Round-Robin From [**Wikipedia**](https://kb.linuxvirtualserver.org/wiki/Weighted_Round-Robin_Scheduling): _The weighted round-robin is designed to better handle servers with different processing capacities. Each server can be assigned a weight, an integer value that indicates the processing capacity. Servers with higher weights receive new connections first than those with less weights, and servers with higher weights get more connections than those with less weights and servers with equal weights get equal connections. The pseudo code of weighted round-robin scheduling is as follows:_ Supposing that there is a server set `S = {S0, S1, …, Sn-1}`; `W(Si)` indicates the weight of `Si`; `i` indicates the server selected last time, and `i` is initialized with -1; `cw` is the current weight in scheduling, and `cw` is initialized with zero; `max(S)` is the maximum weight of all the servers in `S`; `gcd(S)` is the greatest common divisor of all server weights in `S`; ```csharp while (true) { i = (i + 1) mod n; if (i == 0) { cw = cw - gcd(S); if (cw <= 0) { cw = max(S); if (cw == 0) return NULL; } } if (W(Si) >= cw) return Si; } ``` _For example, the real servers, A, B and C, have the weights, 4, 3, 2 respectively, a scheduling sequence will be AABABCABC in a scheduling period (mod sum(Wi))._ _In an optimized implementation of the weighted round-robin scheduling, a scheduling sequence will be generated according to the server weights after the rules of IPVS are modified. The network connections are directed to the different real servers based on the scheduling sequence in a round-robin manner._ _The weighted round-robin scheduling is better than the round-robin, when the processing capacity of real servers are different. However, it may lead to dynamic load imbalance among the real servers if the load of the requests varies highly. In short, there is the possibility that a majority of requests requiring large responses may be directed to the same real server._ _Actually, the round-robin is a special instance of the weighted round-robin scheduling, in which all the weights are equal._