We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1dca137 commit f19ed8dCopy full SHA for f19ed8d
volcenginesdkarkruntime/_utils/_model_breaker.py
@@ -1,4 +1,5 @@
1
from datetime import datetime, timedelta
2
+import random
3
4
5
class ModelBreaker:
@@ -17,7 +18,12 @@ def reset(self, duration):
17
18
def get_allowed_duration(self):
19
# 计算当前时间与 allow_time 之间的持续时间
20
allow_duration = self.allow_time - datetime.now()
21
+
22
+ # 添加一个随机抖动,该抖动的范围为 0 到 10 秒,概率密度函数为 f(x) = x/50 (0 <= x <= 10)
23
+ # 约有 1/100 的请求会在结束熔断的第一秒内发起重试
24
+ jitter = timedelta(seconds=random.triangular(0, 10, 10))
25
26
# 如果持续时间为负,则返回一个零时长的 timedelta 对象
27
if allow_duration.total_seconds() < 0:
- return timedelta(0)
- return allow_duration
28
+ return timedelta(0) + jitter
29
+ return allow_duration + jitter
0 commit comments