【问题标题】:setup a Autoscale Policy assessment设置自动缩放策略评估
【发布时间】:2021-01-06 09:14:50
【问题描述】:

风险建模系统使用缩放计算系统,该系统根据计算系统的当前负载或利用率实施自动缩放策略。

系统以实例给定的多个计算实例开始。系统每秒轮询实例以查看该秒的平均利用率,并执行如下所示的缩放。一旦采取任何行动,系统将停止轮询 10 秒。在此期间,实例的数量不会改变。

平均利用率 > 60%:如果加倍的值不超过 2 * 10^8,则将实例数加倍。这是一个动作。如果实例数超过此限制加倍,则不执行任何操作。

平均利用率

25%

将该系统每秒的平均利用率值作为一个数组确定时间范围结束时的实例数。

例如,系统从实例 = 2 开始。平均利用率为 averageUtil = [25, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 76, 80] .

在第一秒,利用率为 25,因此不采取任何行动。

At the second second, averageUtil[1] = 23 < 25, so instances = 2 / 2 = 1. The next 10 seconds, averageUtil[2]..averageUtil[11], no polling is done.

在 averageUtil(12] = 76, 76 > 60 时,实例数增加了一倍。没有更多的读数需要考虑,2 是最终答案。

Example 1:
Input: averageUtil=[1, 3, 5, 10, 80]
Output: 2
Explanation:
Here instance = 1 and averageUtil = [5, 10, 80]. At the 1st and 2nd seconds of the time period, no action will be taken, Even though the utilization is less than 25%, the number of instance is 1. During the 3rd second, the no of instance will be doubled to 2.

Constraints:
1 <= instances <= 10^5
1 <= n <= 10^5
1 <= averageUtil[i] <= 10

【问题讨论】:

    标签: python python-3.x data-structures


    【解决方案1】:
    from math import ceil
    
    def util(utilization, instance):
        i=0
        while i < len(utilization):
            if utilization[i] < 25 and instance > 1:
                instance = ceil(instance/2)
                i += 10
            elif utilization[i] > 60 and instance < 2**8:
                instance *= 2
                i += 10
            i+=1
        return instance
    
    test= util([25, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 76, 80], 2)
    print(test)
    

    【讨论】:

    • 不能接受纯代码回答,您应该添加一些描述
    • @AminM 这是对上述问题的解决方案。你想要什么描述?
    • 感谢您提供此代码 sn-p,它可能会提供一些有限的即时帮助。 proper explanation 将通过展示为什么这是解决问题的好方法,并使其对有其他类似问题的未来读者更有用,从而大大提高其长期价值。请edit您的回答添加一些解释,包括您所做的假设。
    猜你喜欢
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 2021-10-30
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 2020-07-21
    相关资源
    最近更新 更多