perf(lps): Step1 — 폴백 데드라인 + fail-fast로 검색 지연 상한

G마켓 챌린지가 안 풀린 채 25~70초를 먹던 문제에 상한을 씌운다. 폴백은 '있으면 좋은'
보강이라 데드라인으로 잘라도 안전(그 몰만 스킵).

- handler: 각 폴백 크롤에 fallback_deadline_sec(기본 15s) wait_for. 초과 시 스킵.
  _timed_search 예외를 BaseException 로(CancelledError 계측 포함).
- 폴백 어댑터 max_block_retries=0(챌린지 대기 2배 방지), ESM ready_timeout 22→12s, st11 20→15s.
- 테스트: 느린 폴백 데드라인 스킵 1종.

실측(동시성2·4상품): 상품당 p50 84.6s→34.2s(~2.5x), 벽시계 181s→65s(~2.8x),
처리량 1.3→3.7 상품/분, 1000건 $7.12→$5.06(~29%↓, 실패 챌린지 대역폭 절감).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Fable 5 committed 2026-07-09 17:01:09 +09:00
1 parent ba67275cd8
commit 4b8dee8583
5 files changed
+39 -9

No files matched your search

+11 -3
View File
@@ -56,6 +56,7 @@ def build_search_handler(
fallback_adapters: dict[str, SearchAdapter] | None = None,
ai_model: str = "",
proxy_cost_per_gb: float = 0.0,
fallback_deadline_sec: float = 15.0,
):
"""검색 핸들러 생성.
judge: SimilarityJudge(같은 상품 판정) / keyword_gen: KeywordGenerator(정밀·광역 재검색어) /
@@ -82,8 +83,8 @@ def build_search_handler(
res = await adapter.search(query, limit=limit)
metrics.add_fetch(source, getattr(adapter, "last_bytes", 0), int((time.monotonic() - t0) * 1000), crawl=crawl, via_proxy=via_proxy)
return res
except Exception:
metrics.add_fetch(source, 0, int((time.monotonic() - t0) * 1000), crawl=crawl, via_proxy=via_proxy)
except BaseException: # CancelledError(데드라인 취소) 포함 — 소요/바이트는 계측하고 재전파
metrics.add_fetch(source, getattr(adapter, "last_bytes", 0), int((time.monotonic() - t0) * 1000), crawl=crawl, via_proxy=via_proxy)
raise
async def _search_round(query: str, metrics: SearchMetrics):
@@ -124,8 +125,15 @@ def build_search_handler(
return matched
async def _crawl_match(src, adapter):
# 폴백은 '있으면 좋은' 보강이라 데드라인을 건다 — 초과 시 그 몰만 스킵(전체 지연에 상한).
try:
crawled = await _timed_search(adapter, query, src, metrics, crawl=True)
crawled = await asyncio.wait_for(
_timed_search(adapter, query, src, metrics, crawl=True),
timeout=fallback_deadline_sec,
)
except asyncio.TimeoutError:
LOG.w(f"[fallback:{src}] 데드라인 {fallback_deadline_sec:.0f}s 초과 → 스킵")
return []
except Exception as ex:
LOG.w(f"[fallback:{src}] 크롤 실패(무시): {type(ex).__name__}: {ex}")
return []