Performance Optimization
Best practices for optimizing upload performance with ChunkFlow.
Chunk Size Optimization
Network-Based
- Fast network (> 10 Mbps): 5-10MB chunks
- Medium network (1-10 Mbps): 1-5MB chunks
- Slow network (< 1 Mbps): 256KB-1MB chunks
typescript
const task = manager.createTask(file, {
chunkSize: detectOptimalChunkSize(),
});File-Based
- Small files (< 50MB): 1-2MB chunks
- Medium files (50-500MB): 2-5MB chunks
- Large files (> 500MB): 5-10MB chunks
Concurrency Optimization
typescript
// Fast network
const task = manager.createTask(file, {
concurrency: 10,
});
// Slow network
const task = manager.createTask(file, {
concurrency: 2,
});Memory Optimization
- Use streaming for large files
- Limit concurrent uploads
- Clean up completed tasks
- Use Web Workers for hash calculation
Network Optimization
- Enable HTTP/2 or HTTP/3
- Use CDN for static assets
- Implement connection pooling
- Enable compression
Best Practices
- Let dynamic chunking adapt automatically
- Monitor upload speed and adjust
- Use instant upload for deduplication
- Implement proper error handling
- Test with various network conditions
Monitoring
typescript
task.on("progress", ({ speed, remainingTime }) => {
console.log(`Speed: ${formatSpeed(speed)}`);
console.log(`ETA: ${formatTime(remainingTime)}`);
});