Skip to content

Conversation

@twdamhore
Copy link
Owner

@twdamhore twdamhore commented Jan 20, 2026

Summary

Fixes high memory usage (2GB+) when serving large ISO files.

Root cause: 32MB chunks are too large for TCP. Hyper buffers received data while waiting to write to socket, causing memory to accumulate.

Fix:

  • CHUNK_SIZE: 32MB → 8MB
  • CHANNEL_CAPACITY: 2 (~16MB max in flight)
  • Simplified comments (removed hardcoded values)

Expected results

  • Memory usage significantly reduced
  • Proper backpressure from TCP layer to disk reads

Test plan

# Start server with new binary
systemctl restart serabutd

# Monitor memory while serving ISO
watch -n1 'ps -o rss= -p $(pgrep serabutd)'

# Trigger ISO download
curl http://localhost:4123/iso/ubuntu-22.04/ubuntu-22.04.5-live-server-amd64.iso -o /dev/null

🤖 Generated with Claude Code

The 32MB chunk size was causing memory bloat because Hyper buffers
received data while waiting to write to the TCP socket.

Changes:
- CHUNK_SIZE: 32MB -> 8MB
- CHANNEL_CAPACITY: constant (2) for ~16MB max in flight
- Simplified comments to not hardcode capacity values
- Updated test to use 20MB file (3 chunks with new size)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@twdamhore twdamhore force-pushed the fix-chunk-size-for-tcp branch from eebf4ab to 22cddd9 Compare January 20, 2026 20:00
@twdamhore twdamhore merged commit 4c228fc 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