MonaServer: A Beginner’s Guide to Real-Time Streaming

How to Set Up MonaServer for Low-Latency Video and Audio

1. Overview

MonaServer is a lightweight, high-performance multimedia server that supports low-latency streaming over protocols like WebSocket, WebRTC (via plugins), RTMP, and raw TCP/UDP. This guide assumes a basic Linux server (Ubuntu 22.04) and a single-stream use case; adapt for multiple streams or clusters.

2. Prerequisites

  • Ubuntu 22.04 or similar Linux distro
  • Root or sudo access
  • 1–4 CPU cores, 1–4 GB RAM (more for heavy loads)
  • Open ports: ⁄443 (HTTP/HTTPS), 1935 (RTMP), 8088 (MonaServer default), plus any custom ports
  • Optional: TLS certificate (Let’s Encrypt) for secure WebSocket/WSS and HTTPS

3. Install MonaServer

  1. Download the latest MonaServer release for Linux from the official site or GitHub.
  2. Extract and move the binary to /usr/local/bin:

    Code

    sudo tar xzf monaserver-*.tar.gz -C /opt sudo ln -s /opt/monaserver/monaserver /usr/local/bin/monaserver
  3. Create a systemd service file /etc/systemd/system/monaserver.service:

    Code

    [Unit] Description=MonaServer After=network.target[Service] ExecStart=/usr/local/bin/monaserver -c /opt/monaserver/config.xml Restart=on-failure User=www-data Group=www-data

    [Install] WantedBy=multi-user.target

  4. Reload systemd and start MonaServer:

    Code

    sudo systemctl daemon-reload sudo systemctl enable –now monaserver

4. Basic Configuration (config.xml)

  • Set bind addresses and ports (HTTP, WebSocket, RTMP).
  • Enable protocol modules you need (WebSocket, RTMP, UDP).
  • Configure connection limits, timeouts, and logging.
    Example minimal snippets:

Code

1000

5. Low-Latency Settings

  • Use WebSocket or WebRTC where possible for sub-200ms latency.
  • For RTMP ingest + WebSocket delivery: lower buffer sizes and smaller chunk sizes.
  • Tune socket options in config: TCP_NODELAY (disable Nagle), reduce send/receive buffer sizes.
  • Reduce media buffering on client players (set play buffer 100–300ms).
  • Prefer H.264 (low-complexity profiles) or VP8/Opus for low-delay; lower GOP size and enable keyframe frequency (e.g., every 1–2 seconds).
  • Use RTP/UDP for very low latency when acceptable (lossy).
  • Set keepalive and timeout values higher for unstable networks to avoid reconnections.

6. TLS and Security

  • Use Let’s Encrypt for certificates; enable WSS and HTTPS in config.
  • Restrict admin interfaces to localhost or VPN.
  • Enable client authentication where needed (token-based or JWT).
  • Limit max connections per IP and use rate-limiting.

7. Scaling and Performance

  • Enable multi-threading in MonaServer if available; run multiple worker processes.
  • Use a load balancer (nginx or haproxy) in front for TLS termination and to distribute connections.
  • Offload encoding to dedicated transcoders (FFmpeg) if you need multiple output formats/bitrates.
  • Monitor CPU, memory, network I/O; consider vertical scaling or horizontal clustering.

8. Testing and Monitoring

  • Test latency with real clients (browser WebSocket/WebRTC, ffplay, OBS). Measure end-to-end RTT and playback buffer.
  • Use logs and metrics: enable access logs, expose Prometheus metrics if supported, or scrape system stats.
  • Run load tests (e.g., Tsung or custom scripts) to find bottlenecks.

9. Example: Browser WebSocket Playback

  • Publish: use OBS or FFmpeg to push RTMP to MonaServer.
  • Deliver: WebSocket client connects to ws(s)://yourserver:8088/stream and handles raw packets or uses a JS player that supports MonaServer formats. Reduce client buffer and set small decode queues.

10. Troubleshooting

  • High latency: check encoder GOP, network jitter, buffering settings, TCP_NODELAY.
  • Packet loss: switch to UDP/RTP or tune retransmission on application layer.
  • Connection drops: inspect timeouts, maxConnections, system file descriptor limits (increase ulimit -n).

If you want, I can generate a ready-to-use config.xml and systemd unit tailored to your server (specify OS, public ports, and protocols you need).

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *