Overview
Backpressure occurs when frames are enqueued faster than they can be encoded, leading to:- Memory buildup (queue grows unbounded)
- Out of memory errors (heap exhausted)
- Slow performance (system thrashing)
The Problem
The Solution
Monitoring Queue Size
TheencodeQueueSize property shows pending frames:
Simple Throttling
Wait when queue exceeds threshold:Event-Based Backpressure
Usedequeue events for precise control:
Adaptive Throttling
Adjust queue size based on system load:Batch Processing
Process frames in manageable batches:Memory Monitoring
Track memory usage during encoding:Best Practices
Set appropriate queue limits
Set appropriate queue limits
Always close frames immediately
Always close frames immediately
Monitor memory in production
Monitor memory in production
Use batching for large jobs
Use batching for large jobs
For thousands of frames, process in batches of 100-1000.