Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhance] The MinAvailable value for scaling support percent type #185

Open
chrisliu1995 opened this issue Nov 14, 2024 · 10 comments
Open
Assignees

Comments

@chrisliu1995
Copy link
Member

当前用于扩容的MinAvailable是以具体数值的方式生效的。比如,MinAvailable为3,会保证至少存在3个可用游戏服。

但在游戏服数量变化比较明显的情况下,固定的值并不能很好地拟合玩家涌入的速率。因此,我们需要让MinAvailable支持百分比类型,在gameserver总数增多的情况下,最小可用的数量也增多;gameserver总数减少的情况下,最小可用的数量也减少。

@Macroldj
Copy link

Macroldj commented Nov 14, 2024

MinAvailable 的取值必定是小于replicas的取值的,所以 按比例设置的时候按照 0<value<1 取值是合理的。关于具体取值如下情况进行讨论

  1. 取值范围在 0-100% 即 [0,100],对于大于100%的设置毫无意义,但是为了规避这种情况,直接使其强制变成100%,即 200% -> 100%

  2. 在计算过程中产生小数怎么取值?

  • 四舍五入, 优点最直观,在设置的时候不会有歧义。但是当 replicas: 10 MinAvailable: 1% 此时就会是0.
  • 向上取整, 优点有保底容器。当 replicas: 10 MinAvailable: 1% 此时就会是1. 有保底的1个容器,生产安全,但是当设置为91%的时候就会失去意义,都会变成100%。
  • 向下取整, 优点能让MinAvailable永远保持小于replicas,但是在设置小于10%时都会将MinAvailable设置为0.

我觉得可以用 向上取整 的方式进行取整,MinAvailable的设置一般会设置在 30%-50% 91%-100%的情况会少很多。

@chrisliu1995

@chrisliu1995
Copy link
Member Author

首先我们需要确定MinAvailable的语义,表示“最少可用”,最终依然要落实到具体数量上。因此,百分比生效与否,需要计算当前可用gs数量后才能得到结论。

例如,replicas 为10,MinAvailable=91%情况下:

若当前None的数量是9,则可用比例为90% < 91%,所以需要扩容。至于扩容几个,需要再次计算。扩容1个,则replicas为11,None的数量为10,可用比例为 90.09%,依然 < 91%;扩容2个,则replicas为12,None的数量为91.6% > 91%. 所以副本数量应该设置为12.

这种逻辑符合MinAvailable的语义。

@jayesh9747
Copy link

can you provide this issue in english so that i can try to understand and make contribution

@chrisliu1995
Copy link
Member Author

can you provide this issue in english so that i can try to understand and make contribution

The MinAvailable currently used for capacity expansion takes effect in the form of specific values. For example, if MinAvailable is 3, it will ensure that there are at least 3 available game servers.

However, when the number of game servers changes significantly, a fixed value cannot fit the rate of player influx well. Therefore, we need to make MinAvailable support the percentage type. When the total number of gameservers increases, the minimum available number also increases; when the total number of gameservers decreases, the minimum available number also decreases.

@jayesh9747
Copy link

@chrisliu1995 can you assign this issue to me ?

@jayesh9747
Copy link

jayesh9747 commented Dec 10, 2024

@chrisliu1995 We aim to express the MinAvailable variable (replicas/servers/pods) as a percentage. The range of the MinAvailable variable should be at least 1 and, at maximum, it can be TotalServers - 1. In other situations, we can calculate the lower bound of the total number of servers. Am I on the right track? Additionally, could you tell me where this logic is implemented in the file system so I can modify it accordingly?

For example, if we initially have 10 servers and set MinAvailable to 30%, the minimum number of available servers should be 10 × 0.30 = 3 10×0.30=3. The range of MinAvailable would then be between 1 (minimum requirement) and 10 − 1 = 9 10−1=9 (maximum allowed value to ensure at least one server can be unavailable). As the total number of servers increases to 20, the calculation adjusts dynamically. With MinAvailable at 30%, the minimum available servers would now be 20 × 0.30 = 6 20×0.30=6. The range would expand to between 1 and 20 − 1 = 19 20−1=19. This ensures flexibility while maintaining availability and scalability.

@jayesh9747
Copy link

@chrisliu1995 can you please reply back ?

@chrisliu1995
Copy link
Member Author

chrisliu1995 commented Dec 11, 2024

First of all, We must know that the purpose of okg scaler is to compute the desire replicas. And MinAvailable value that user set is need to be consider when we compute the replicas. MinAvailable means that the desire number of gameservers whose opstate is None should be bigger or equal than the number of gameservers whose opstate now, or we must add replicas to scale up more new gameservers, which is None by default when created.

Besides, MinAvailable could be integer type, and also be percentage type. I would prefer that when >= 1, it's considered to be integer type, and when >0 & < 1, it's percentage type. And we must verify the value is legal or not according to the principle above. For example, when MinAvailable='4.3', it's illegal.

if x means the number we should add, then we should ensure ( {number of none now} + x ) / ( {total replicas now} + x ) >= MinAvailable(percentage)

@jayesh9747
Copy link

Our task is to compute how many extra game servers are required for scaling (variable: x). Can you suggest where this logic should be implemented and provide the correct path for this repository? Additionally, I have written a pseudocode function for calculating and validating that the MinAvailable value is not illegal. If MinAvailable > 1, it should be treated as an integer, and if it is between 0 and 1, it should be treated as a percentage

func ValidateMinAvailable(MinAvailable float64) error {
    if MinAvailable >= 1 {
        // Integer type
        return nil
    } else if MinAvailable > 0 && MinAvailable < 1 {
        // Percentage type
        return nil
    }
    return fmt.Errorf("Invalid MinAvailable value: %f. It must be >= 1 or between 0 and 1", MinAvailable)
}

func ComputeReplicas(NoneNow, TotalReplicasNow int, MinAvailable float64) (int, error) {
    // Validate MinAvailable
    if err := ValidateMinAvailable(MinAvailable); err != nil {
        return 0, err
    }

    if MinAvailable >= 1 {
        // Integer type
        x := int(math.Max(0, MinAvailable-float64(NoneNow)))
        return x, nil
    } else {
        // Percentage type
        if MinAvailable*float64(TotalReplicasNow) > float64(NoneNow) {
            x := math.Ceil((MinAvailable*float64(TotalReplicasNow) - float64(NoneNow)) / (1 - MinAvailable))
            return int(x), nil
        }
        return 0, nil // No scaling required
    }
}

Am I correct ?

@jayesh9747
Copy link

cc : @chrisliu1995

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants