fix: RIIN order/goods 全局限速(并发20→5+150ms间隔,峰值≤6.7QPS);暂停 recent-sync/verify 调度(分销侧反馈调用量过大)

This commit is contained in:
yeuimu
2026-10-23 10:57:46 +00:00
parent 1a13075926
commit eb97ee1647
2 changed files with 21 additions and 1 deletions
+19 -1
View File
@@ -8,6 +8,7 @@
from __future__ import annotations
import json
import threading
import time
from datetime import datetime, timedelta, timezone
from typing import Any, Callable, TypeVar
@@ -21,7 +22,8 @@ from flows.shared.mappers import map_sds_channel_type
T = TypeVar("T")
GOODS_CONCURRENCY = 20
GOODS_CONCURRENCY = 5
GOODS_MIN_INTERVAL_MS = 150 # 相邻两次 order/goods 调用全局最小间隔(峰值 ≤ ~6.7 次/秒)
PAGE_DELAY_MS = 500
MAX_RETRIES = 3
RETRY_DELAY_MS = 3000
@@ -144,8 +146,24 @@ def fetch_sds_all_pages(client: SdsMngClient, params: dict[str, Any]) -> list[An
# ---------- RIIN 商品 ----------
# 全局限速:RIIN 分销侧反馈 distribution/order/goods 逐单调用对其服务器压力过大,
# 所有线程共享节拍,相邻两次调用至少间隔 GOODS_MIN_INTERVAL_MS。
_goods_pace_lock = threading.Lock()
_goods_last_call_at = 0.0
def _pace_goods_call() -> None:
global _goods_last_call_at
with _goods_pace_lock:
wait = _goods_last_call_at + GOODS_MIN_INTERVAL_MS / 1000 - time.monotonic()
if wait > 0:
time.sleep(wait)
_goods_last_call_at = time.monotonic()
def fetch_goods_for_order(client: RiinDisClient, order_id: str) -> list[Any]:
try:
_pace_goods_call()
resp = client.get_order_goods(order_id)
return list(resp.data)
except Exception as err: # noqa: BLE001