Application of load-balanced LVs (v): The law of weighted scheduling algorithm

Source: Internet
Author: User
Tags gcd

Back to LVS series article: http://www.cnblogs.com/f-ck-need-u/p/7576137.html

The weighted scheduling algorithm is a very common scheduling algorithm. If there are only two back-ends, the order of dispatch is easy, but if the back end is more than 2, it may not be dispatched in the order it was imagined.

So, the paper discusses how to dispatch the weighted scheduling algorithm in the end.

1. Weighted Scheduling algorithm formula

First, give an official LVS manual for the weighted scheduling algorithm formula:

Suppose there is a set of servers S = {S0, S1, ..., Sn-1},w (SI) represents the weight of the server Si, a
Indicates that the variable i represents the last server selected, indicating that the variable CW represents the right value for the current dispatch, Max (S)
Represents the maximum weight of all servers in the collection S, gcd (s) represents the maximum of all server weights in the collection s
Number of conventions. The variable i is initialized to -1,CW initialized to zero.

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, a, B, c three back-end weight ratio is 2:3:4 , then a dispatch loop within the scheduling sequence is cbcabcabc.

If you don't want to find the rules in algorithmic formulas, look below.

2. Weighted scheduling Popular law

Remember three weight scheduling rules:
1. First Numerator
2. Start scheduling from Maximum weight
3. The back end of the same weight, dispatched from front to back

For example, three back ends A:B:C=2:3:4 . I can't numerator here.

    1. Dispatch C
      After scheduling, the ratios become A:B:C=2:3:3 , B and C weights are the same, starting with B scheduling
    2. Dispatch b
      After scheduling, the ratio becomes A:B:C=2:2:3 , so the next time you schedule C
    3. Dispatch C
      After the dispatch, the ratio becomes A:B:C=2:2:2 , the next time starting from a
      When the weights are all adjusted to the same value, they are continuously looped in order until all weights are dispatched
    4. Dispatch A, after scheduling, the ratio becomesA:B:C=1:2:2
    5. Dispatch B, after dispatch, the ratio becomesA:B:C=1:1:2
    6. Dispatch C, after dispatch, the ratio becomesA:B:C=1:1:1
    7. Dispatch A, after scheduling, the ratio becomesA:B:C=0:1:1
    8. Dispatch B, after dispatch, the ratio becomesA:B:C=0:0:1
    9. Dispatch C, after dispatch, the ratio becomesA:B:C=0:0:0
    10. Enter the next scheduling loop, in order: CBCABCABC

Therefore, the scheduling order for each scheduling cycle is: CBCABCABC

The scheduling process is as follows:

To give an example,A:B:C:D=2:4:6:8

First numerator, getA:B:C:D=1:2:3:4

    1. Dispatch D
    2. Dispatch C
    3. Dispatch D
    4. Dispatch b
    5. Dispatch C
    6. Dispatch D
    7. Dispatch a
    8. Dispatch b
    9. Dispatch C
    10. Dispatch D

Therefore, the scheduling sequence is DCDBCDABCD.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.