Skip to content

Commit f19ed8d

Browse files
committed
fix: simple jitter
1 parent 1dca137 commit f19ed8d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

volcenginesdkarkruntime/_utils/_model_breaker.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timedelta
2+
import random
23

34

45
class ModelBreaker:
@@ -17,7 +18,12 @@ def reset(self, duration):
1718
def get_allowed_duration(self):
1819
# 计算当前时间与 allow_time 之间的持续时间
1920
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+
2026
# 如果持续时间为负,则返回一个零时长的 timedelta 对象
2127
if allow_duration.total_seconds() < 0:
22-
return timedelta(0)
23-
return allow_duration
28+
return timedelta(0) + jitter
29+
return allow_duration + jitter

0 commit comments

Comments
 (0)