크롤 쉼에 동시 렌더링 상한과 페이지 캐시를 둔다 - #30
Closed
nam-jaehyun wants to merge 2 commits into
Closed
nam-jaehyun wants to merge 2 commits into
nam-jaehyun wants to merge 2 commits into
Conversation
Chromium 한 대가 모든 요청을 받는데 동시 수 제한이 없어, 몰리면 탭이 서로 CPU 를 뺏다가 30초 타임아웃에 함께 걸렸다(32 병렬에서 중앙값 20.6초, 최대 26.5초). `gate.py` 의 두 장치를 앞에 둔다. - Gate: 동시에 MAX_CONCURRENT_PAGES(8)장만 렌더링하고, 나머지는 QUEUE_TIMEOUT_MS(15초)까지 기다린 뒤 「busy」로 거절한다. 부르는 쪽 (KloudChat)은 읽지 못한 페이지처럼 요약문으로 물러난다. - PageCache: 성공한 스크랩을 URL·formats·본문 플래그로 CACHE_TTL_S (15분) 동안 메모리에 둔다. 같은 시간대에 같은 것을 묻는 사용자들은 같은 상위 결과를 읽는다. /health 가 렌더링 중·대기 중·캐시 항목 수를 보인다. 운영 측정(8코어): 16 병렬 콜드 p50 7.6→2.2초, 32 병렬 콜드 p50 20.6→15.5초·최대 26.5→19.8초(전부 성공), 캐시 적중 시 0.3초. Dockerfile 이 파일을 하나씩 복사하므로 gate.py 를 목록에 넣었다 — 처음 배포에서 빠뜨려 쉼이 재시작 루프에 들어갔었다. 확인: tests/test_gate.py 5건(상한·대기·거절, TTL, 키, 축출), ruff 통과.
이미지·글꼴·미디어는 모델에 전달되지 않는다 — 쉼은 마크다운 본문만 돌려주고 KloudChat 은 그 텍스트만 검색 결과에 붙인다. 그러니 브라우저가 내려받을 이유가 없다(`text_mode=True`, 스크립트는 그대로 돈다). 운영에서 같은 12쪽을 전후로 읽어 비교: 본문 길이는 동일(위키백과 463,355→463,455자, 파이썬 71,202→71,202자 등, 12쪽 모두 본문 있음), 합계 시간 64.4→59.2초, 무거운 쪽은 10.5→8.0초·11.4→8.4초.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#29(yandex) 위에 쌓인 PR입니다.
변경
services/crawl4ai-shim/gate.py:Gate(동시 렌더링 상한 + 바운드된 대기)와PageCache(TTL·LRU).app.py: 캐시 적중이면 브라우저를 열지 않고 답한다. 상한을 넘어QUEUE_TIMEOUT_MS안에 자리가 안 나면{"success": false, "error": "busy…"}. 성공한 스크랩은 캐시에 넣는다./health에pages{active,waiting,limit}·cache{entries,ttl_s}.docker-compose.yml:MAX_CONCURRENT_PAGES=8,QUEUE_TIMEOUT_MS=15000,CACHE_TTL_S=900.gate.py복사 추가.docs/tools.md문단.측정 (운영, 8코어, KloudChat api 컨테이너에서 병렬 호출)
모두 성공. 32 병렬에서는 8장씩 네 차례로 나뉘어 도는 모양이라 최대값은 대기 시간이 대부분이다. 더 늘리려면 쉼 복제(브라우저 여러 대)가 다음 단계다.
확인
tests/test_gate.py5건, ruff 통과. 운영에 배포해 위 표를 쟀다.추가: 텍스트 모드
이미지·글꼴·미디어는 모델에 전달되지 않으므로(쉼은 마크다운만 돌려준다) 브라우저가 내려받지 않게
text_mode=True를 켰다. 스크립트는 그대로 돈다. 같은 12쪽 전후 비교: 본문 길이 동일(12쪽 모두 본문 있음), 합계 64.4→59.2초, 무거운 쪽 10.5→8.0초·11.4→8.4초.