Skip to content

Commit

Permalink
minor: 后台检测缓存清理优化
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguo367 committed Sep 25, 2024
1 parent 9f80333 commit 3859a7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bkmonitor/alarm_backends/core/detect_result/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from alarm_backends.core.cache import key

CONST_MAX_LEN_CHECK_RESULT = 60 # 检测结果缓存,默认只保留60条数据
CONST_MAX_LEN_CHECK_RESULT = 30 # 检测结果缓存,默认只保留30条数据

ANOMALY_LABEL = "ANOMALY" # 异常标识

Expand Down
12 changes: 10 additions & 2 deletions bkmonitor/alarm_backends/core/detect_result/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def clean_expired_detect_result(strategy_range=None):
pipeline = client.pipeline()
total = len(strategies)
step = int(total / 100)
wait_signals = list(range(step, total, step))
if step < 5:
wait_signals = []
else:
wait_signals = list(range(step, total, step))
last_sleep_time = time.time()
for s_id, strategy in enumerate(strategies):
# 按照策略的检测与恢复周期配置,决定保留多少个周期的检测结果
point_remain = detect_result_point_required(strategy)
Expand Down Expand Up @@ -101,7 +105,11 @@ def clean_expired_detect_result(strategy_range=None):

# redis 性能缓冲, 避免清理任务占满redis cpu
if s_id in wait_signals:
time.sleep(1)
now = time.time()
clean_duration = now - last_sleep_time
if clean_duration > 1:
time.sleep(clean_duration)
last_sleep_time = now

@staticmethod
def clean_md5_to_dimension_cache():
Expand Down

0 comments on commit 3859a7c

Please sign in to comment.