Files
ryan.mcgeeandClaude Sonnet 4.6 de7d16c45f perf: cap Node.js heap and clean up dead HLS proxy connections
- start.sh: --max-old-space-size=384 so V8 GCs aggressively instead of
  deferring until the ~1.4 GB default ceiling
- HLS proxy: destroy the upstream mediamtx request when the client closes
  the connection; add proxyRes error handler to avoid uncaught emissions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 17:51:05 -05:00

40 lines
1.1 KiB
Bash

#!/bin/sh
set -e
HWACCEL="${HWACCEL:-none}"
# Auto-detect the best available hardware accelerator by checking device nodes.
# /dev/nvidia0 → NVENC (NVIDIA, requires NVIDIA Container Toolkit + deploy config)
# /dev/dri/renderD128 → VAAPI (Intel/AMD, requires /dev/dri device passthrough)
# falls back to software (mediamtx built-in recorder, no FFmpeg)
detect_hwaccel() {
if [ -e /dev/nvidia0 ] && [ -e /dev/nvidiactl ]; then
echo "nvenc"
elif [ -e /dev/dri/renderD128 ]; then
echo "vaapi"
else
echo "none"
fi
}
if [ "$HWACCEL" = "auto" ]; then
HWACCEL=$(detect_hwaccel)
echo "[start] auto-detected hardware acceleration: $HWACCEL"
fi
if [ "$HWACCEL" = "none" ]; then
CONFIG=/app/mediamtx.yml
else
CONFIG=/app/mediamtx-hwaccel.yml
echo "[start] hardware acceleration: $HWACCEL"
fi
# Export so on-ready-hw.sh inherits the resolved value
export HWACCEL
# Start mediamtx in the background; Express handles auth and serves HLS.
mediamtx "$CONFIG" &
# Exec Node.js as the foreground process so Docker tracks it for health/stop.
exec node --max-old-space-size=384 dist/index.js