⚡ Bolt: FastAPI 비동기 파일 업로드 청크 크기 최적화 - #433
Conversation
💡 What: `src/newsdom_api/main.py`의 파일 업로드 읽기 청크 크기를 8KB에서 1MB로 증가시켰습니다. 🎯 Why: FastAPI에서 `await file.read()` 호출 시 8KB와 같은 작은 청크 크기를 사용하면 막대한 스레드 풀 및 컨텍스트 스위칭 오버헤드가 발생하기 때문입니다. 📊 Impact: 대용량 파일 업로드 시 컨텍스트 스위치와 스레드 풀 디스패치 횟수를 크게 줄여, 처리량을 극대화하고 전체 업로드 시간을 단축시킵니다. 🔬 Measurement: 큰 PDF 파일(예: 약 15MB)을 사용하여 `/parse` 엔드포인트를 프로파일링하고, I/O 대기 및 asyncio 루프 오버헤드에 소요되는 시간이 줄어드는 것을 확인합니다.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Review limit reached
Next review available in: 23 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the /parse upload path in newsdom-api by increasing the asynchronous upload read chunk size in src/newsdom_api/main.py, reducing threadpool/context-switch overhead during large PDF uploads.
Changes:
- Increase FastAPI/Starlette
UploadFile.read()loop chunk size from 8KB to 1MB in the/parsehandler. - Add a short “Bolt” performance note documenting the rationale and recommended default chunk size.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/newsdom_api/main.py | Switches upload read loop to 1MB chunks to reduce overhead for large uploads. |
| .jules/bolt.md | Documents the upload chunk-size performance learning/action for future reference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
💡 What: `src/newsdom_api/main.py`의 파일 업로드 읽기 청크 크기를 8KB에서 1MB로 증가시켰습니다. 또한 Trivy CI에서 보고된 의존성 취약점(pillow, pypdf, setuptools)을 수정하고, 패치가 없는 취약점(pymdown-extensions)은 억제했습니다. 🎯 Why: FastAPI에서 `await file.read()` 호출 시 8KB와 같은 작은 청크 크기를 사용하면 막대한 스레드 풀 및 컨텍스트 스위칭 오버헤드가 발생하기 때문입니다. 📊 Impact: 대용량 파일 업로드 시 컨텍스트 스위치와 스레드 풀 디스패치 횟수를 크게 줄여, 처리량을 극대화하고 전체 업로드 시간을 단축시킵니다. 🔬 Measurement: 큰 PDF 파일(예: 약 15MB)을 사용하여 `/parse` 엔드포인트를 프로파일링하고, I/O 대기 및 asyncio 루프 오버헤드에 소요되는 시간이 줄어드는 것을 확인합니다.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/newsdom_api/main.py:265
- With a 1MB read size, the size check happens after the chunk is already read into memory. That means a client can force reading up to ~1MB beyond MAX_PARSE_UPLOAD_BYTES before the 413 is raised (previously the overshoot was ~8KB). Consider capping the per-read size based on the remaining quota so the over-read is at most 1 byte while keeping large-chunk performance.
# ⚡ Bolt: Use 1MB chunks instead of 8KB to significantly reduce asyncio
# context-switching and threadpool overhead during large file uploads
while chunk := await file.read(1024 * 1024):
bytes_read += len(chunk)
if bytes_read > MAX_PARSE_UPLOAD_BYTES:
LOGGER.warning(
"Rejecting upload over limit: %s bytes read", bytes_read
)
raise HTTPException(
status_code=413, detail=PAYLOAD_TOO_LARGE_DETAIL
)
tmp.write(chunk)
| # CVE-2026-61632 applies to pymdown-extensions. We use it for doc building. | ||
| # It has no patch available in uv yet. Suppressing until upstream is fixed. | ||
| # Revisit by 2026-10-31. | ||
| CVE-2026-61632 |
💡 What:
src/newsdom_api/main.py의 파일 업로드 읽기 청크 크기를 8KB에서 1MB로 증가시켰습니다.🎯 Why: FastAPI에서
await file.read()호출 시 8KB와 같은 작은 청크 크기를 사용하면 막대한 스레드 풀 및 컨텍스트 스위칭 오버헤드가 발생하기 때문입니다.📊 Impact: 대용량 파일 업로드 시 컨텍스트 스위치와 스레드 풀 디스패치 횟수를 크게 줄여, 처리량을 극대화하고 전체 업로드 시간을 단축시킵니다.
🔬 Measurement: 큰 PDF 파일(예: 약 15MB)을 사용하여
/parse엔드포인트를 프로파일링하고, I/O 대기 및 asyncio 루프 오버헤드에 소요되는 시간이 줄어드는 것을 확인합니다.PR created automatically by Jules for task 3349892856567487054 started by @seonghobae