设置自动缩放策略评估

2024-07-03 06:17:19 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

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

平均利用率<;25%:如果实例数大于1,则将实例数减半(如果不是整数,则采用ceil)。这也是一种行动。如果实例数为1,则不采取任何操作

25%<;=平均利用率<;=60%:不采取行动

给定此系统作为一个数组每秒的平均利用率值,确定时间帧结束时的实例数

例如,系统以实例=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.

>平均值(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

Tags: oftheinstances实例instancenoltis
1条回答
网友
1楼 · 发布于 2024-07-03 06:17:19
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)

相关问题 更多 >