Skip to content

⚡ Bolt: FastAPI 비동기 파일 업로드 청크 크기 최적화 - #433

Open
seonghobae wants to merge 2 commits into
developfrom
bolt-upload-chunk-size-3349892856567487054
Open

⚡ Bolt: FastAPI 비동기 파일 업로드 청크 크기 최적화#433
seonghobae wants to merge 2 commits into
developfrom
bolt-upload-chunk-size-3349892856567487054

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 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

💡 What: `src/newsdom_api/main.py`의 파일 업로드 읽기 청크 크기를 8KB에서 1MB로 증가시켰습니다.
🎯 Why: FastAPI에서 `await file.read()` 호출 시 8KB와 같은 작은 청크 크기를 사용하면 막대한 스레드 풀 및 컨텍스트 스위칭 오버헤드가 발생하기 때문입니다.
📊 Impact: 대용량 파일 업로드 시 컨텍스트 스위치와 스레드 풀 디스패치 횟수를 크게 줄여, 처리량을 극대화하고 전체 업로드 시간을 단축시킵니다.
🔬 Measurement: 큰 PDF 파일(예: 약 15MB)을 사용하여 `/parse` 엔드포인트를 프로파일링하고, I/O 대기 및 asyncio 루프 오버헤드에 소요되는 시간이 줄어드는 것을 확인합니다.
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings July 26, 2026 21:00
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c21e011c-5638-43fd-98b6-fe5152c5d24a

📥 Commits

Reviewing files that changed from the base of the PR and between 04491c0 and d06fcd2.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • .jules/bolt.md
  • .trivyignore
  • src/newsdom_api/main.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-upload-chunk-size-3349892856567487054

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /parse handler.
  • 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 루프 오버헤드에 소요되는 시간이 줄어드는 것을 확인합니다.
Copilot AI review requested due to automatic review settings July 26, 2026 21:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread .trivyignore
Comment on lines +24 to +27
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants