Memory Management
Palmr implements an intelligent memory management system that prevents crashes during large file downloads (3GB+ by default), maintaining unlimited download capacity through adaptive resource control and an automatic queue system.
How It Works
Automatic Resource Detection
The system automatically detects available container/system memory and configures appropriate limits based on available infrastructure:
System Configuration
The system supports two configuration approaches that you can choose based on your needs:
Manually configure all parameters for total control over the system:
Manual configuration offers total control and predictability for specific environments where you know exactly the available resources.
Download Queue System
How It Works
The memory management system only activates for files larger than the configured minimum size (3GB by default). Smaller files bypass the queue system entirely and download immediately without memory management.
When a user requests a download for a large file but all slots are occupied, the system automatically queues the download instead of returning a 429 error. The queue processes downloads in FIFO order (first in, first out).
Practical Example
Consider a system with 8GB RAM (5 concurrent downloads, queue of 25, 3GB minimum) where users want to download files of various sizes:
System Benefits
User Experience
- Users don't receive errors, they simply wait in queue
- Downloads start automatically when slots become available
- Transparent operation without client changes
- Fair processing order with FIFO queue
Technical Features
- Limited buffers (64KB per stream) for controlled memory usage
- Automatic backpressure control with pipeline streams
- Adaptive memory throttling based on usage patterns
- Forced garbage collection after large downloads
- Smart timeout handling (30 minutes for queued downloads)
- Automatic cleanup of orphaned downloads every 30 seconds
Container Compatibility
The system works with Docker, Kubernetes, and any containerized environment:
Configuration
Environment Variables
Configure the download memory management system using these environment variables:
Variable | Default | Description |
---|---|---|
DOWNLOAD_MAX_CONCURRENT | auto-scale | Maximum number of simultaneous downloads |
DOWNLOAD_MEMORY_THRESHOLD_MB | auto-scale | Memory limit in MB before throttling |
DOWNLOAD_QUEUE_SIZE | auto-scale | Maximum download queue size |
DOWNLOAD_AUTO_SCALE | true | Enable/disable auto-scaling based on system memory |
DOWNLOAD_MIN_FILE_SIZE_GB | 3.0 | Minimum file size in GB to activate memory management |
Configuration Examples by Scenario
Configuration optimized for personal use or small groups (4GB RAM):
Additional Configuration
For optimal performance with large downloads, consider these additional settings:
Monitoring and Logs
System Logs
The system provides detailed logs to track operation:
Configuration Validation
The system automatically validates configurations at startup and provides warnings or errors:
Warnings
DOWNLOAD_MAX_CONCURRENT > 50
: May cause performance issuesDOWNLOAD_MEMORY_THRESHOLD_MB < 128MB
: Downloads may be throttled frequentlyDOWNLOAD_MEMORY_THRESHOLD_MB > 16GB
: System may run out of memoryDOWNLOAD_QUEUE_SIZE > 1000
: May consume significant memoryDOWNLOAD_QUEUE_SIZE < DOWNLOAD_MAX_CONCURRENT
: Queue smaller than concurrent downloads
Errors
DOWNLOAD_MAX_CONCURRENT < 1
: Invalid valueDOWNLOAD_QUEUE_SIZE < 1
: Invalid value
Queue Management APIs
The system provides REST APIs to monitor and manage the download queue:
Get Queue Status
Response:
Cancel Download
Response:
Clear Queue (Admin)
Response:
Troubleshooting
Common Issues
Downloads failing with "Download queue is full"
Cause: Too many simultaneous downloads with a full queue
Solutions:
- Wait for some downloads to finish
- Check for orphaned downloads in queue
- Consider increasing container resources
- Use API to clear queue if necessary
Downloads stay too long in queue
Cause: Active downloads are slow or stuck
Solutions:
- Check logs for orphaned downloads
- Use API to cancel specific downloads
- Check client network connections
- Monitor memory throttling
Very slow downloads
Cause: Active throttling due to high memory usage
Solutions:
- Check other processes consuming memory
- Consider increasing container resources
- Monitor throttling logs
- Check number of simultaneous downloads
Summary
This system enables unlimited downloads (including 50TB+ files) without compromising system stability through:
Key Features
- Auto-configuration based on available resources
- Automatic FIFO queue system for pending downloads
- Adaptive control of simultaneous downloads
- Intelligent throttling when needed
System Benefits
- Management APIs to monitor and control queue
- Automatic cleanup of resources and orphaned downloads
- Full compatibility with Docker/Kubernetes
- Perfect user experience with no 429 errors
The system maintains high performance for small/medium files while preventing crashes with gigantic files, offering a seamless experience where users never see 429 errors, they simply wait in queue until their download starts automatically.