Broadcast Fixes // StreamRelay Lab
Mounting /dev/shm tmpfs for Zero-IOPS LL-HLS Segment Rings
Keeping your 7-second live HLS segment buffer in kernel RAM eliminates 432,000+ daily disk writes and guarantees sub-millisecond .m4s reads at 3,000 viewers.
Measured MediaMTX & FFmpeg Telemetry
Even fast NVMe disks suffer latency spikes during system backups or log flushes. Serving ephemeral live segments out of tmpfs keeps segment creation atomic and zero-latency.
| Subsystem / Signal | Measured Target | Operational Impact |
|---|---|---|
| Segment Read/Write Latency | < 0.05 ms (RAM speed) | Zero NVMe write amplification |
| RAM Required per 10 Mbps Stream | 40 - 95 MB | Reserve 512 MB tmpfs ceiling |
| systemd Pre-Start Hook | ExecStartPre=mkdir -p | Ensures directory exists across reboots |
Step-by-Step Triage & Config Remediation
- Create dedicated tmpfs or /dev/shm subdir: Use /dev/shm/mediamtx-hls (or mount a 512 MB tmpfs at /mnt/hls-ram) owned by the mediamtx user.
- Update hlsDirectory in mediamtx.yml: Point hlsDirectory directly to the RAM path and restart MediaMTX.
- Monitor tmpfs occupancy: Verify df -h /dev/shm stays under 25% during multi-stream broadcasts.
# /etc/fstab entry for dedicated 512 MB HLS RAM disk: tmpfs /mnt/hls-ram tmpfs defaults,noatime,nosuid,nodev,size=512M,mode=0755 0 0
Diagnostic FAQ
Does tmpfs work for VOD recording too?
No! Never store long-term MP4/fMP4 recordings in tmpfs; write DVR/VOD recordings to persistent disk and keep only live HLS segments in RAM.
How much RAM is safe to allocate to tmpfs on a 4 GB slice?
Allocate 256-512 MB max on a 4 GB node so Go MediaMTX and the OS keep plenty of working memory.