Skip to content

Conversation

@twdamhore
Copy link
Owner

Summary

  • Implement chunked streaming (32MB) for files read from ISOs
  • Add stream_from_iso() and stream_initrd_with_firmware() methods
  • Use spawn_blocking + mpsc channel for async-safe streaming
  • Remove old memory-hungry read_from_iso() methods

Problem

Files read from ISOs were loaded entirely into memory, causing 500MB+ peak memory usage for large files like initrd.

Solution

Stream files in 32MB chunks via bounded mpsc channel (2 chunks max in flight).

Benefits

  • Peak memory: ~64MB instead of file size
  • Better time-to-first-byte (streaming)
  • Improved concurrency (doesn't block async runtime)
  • Content-Length header preserved for all responses

Test plan

  • cargo build passes
  • cargo test passes (62 tests)
  • cargo clippy clean
  • Manual test: request large file from ISO, verify memory stays low

🤖 Generated with Claude Code

twdamhore and others added 3 commits January 20, 2026 10:28
Previously, files read from ISOs were loaded entirely into memory,
causing 500MB+ peak memory usage for large files like initrd.

Changes:
- Add stream_from_iso() method that reads in 32MB chunks via mpsc channel
- Add stream_initrd_with_firmware() for streaming initrd + firmware concatenation
- Update route handlers to use ReceiverStream for streaming responses
- Use spawn_blocking for synchronous ISO reads (fixes async runtime blocking)
- Remove old read_from_iso() and read_initrd_with_firmware() methods

Benefits:
- Peak memory reduced from file size to ~64MB (2 chunks in flight)
- Better time-to-first-byte (streaming starts after first chunk)
- Improved concurrency (doesn't block async runtime)
- Content-Length header still provided for all responses

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Restore debug logging for file-not-found errors in ISO reads
- Add comments explaining why ISO is opened twice (FileBlockIo is not Send)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The "Marked MAC ... as completed" message was logged in both the route
handler and the service layer. Removed the route handler copy since
the service layer is the appropriate location for this log.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@twdamhore twdamhore merged commit 09f9d82 into main Jan 20, 2026
2 checks passed
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.

1 participant