Skip to content

Conversation

@twdamhore
Copy link
Owner

Summary

  • Fixed high memory usage when serving ISO files directly (e.g., /iso/ubuntu-22.04/ubuntu-22.04.5-live-server-amd64.iso)
  • serve_iso_file() was using ReaderStream which buffered ~1.9GB for a 2.6GB ISO
  • Now uses chunked streaming with 32MB chunks and bounded channel for backpressure
  • Memory capped at ~96MB (same as stream_from_iso())

Test plan

  • Serve a large ISO file and monitor memory with watch -n1 'ps -o rss= -p $(pgrep serabutd)'
  • Verify memory stays under ~100MB instead of growing to GB range
  • Run cargo test - all 62 tests pass

🤖 Generated with Claude Code

twdamhore and others added 3 commits January 20, 2026 11:39
serve_iso_file() was using ReaderStream which could buffer large
amounts of data in memory. For a 2.6GB ISO file, memory usage
peaked at 1.9GB.

Now uses the same chunked streaming approach as stream_from_iso():
- 32MB chunks via spawn_blocking
- Bounded mpsc channel (capacity 2) for backpressure
- Max ~96MB in memory (3 chunks: 2 in channel + 1 being read)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract common file streaming logic into stream_file_to_channel()
- Reuse helper in stream_iso_file() and stream_initrd_with_firmware()
- Add test_stream_file_to_channel() for the helper function
- Add test_stream_iso_file() to verify chunked streaming works
- Add test_stream_iso_file_not_found() for error handling

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Simplify stream_file_to_channel return type to Result<(), Error>
- Replace offset tracking with bytes_remaining (cleaner since read_exact advances position)
- Add test_stream_file_to_channel_multiple_chunks with 70MB file (3 chunks)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@twdamhore twdamhore merged commit 2417ad3 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