Wednesday, September 5, 2012

Multi-worker live streaming in master

A few days ago I have merged auto-push branch in master. Several people reported it's pretty stable. Now it's possible to do multi-worker live streaming with nginx-rtmp. That can make you achieve really huge traffic. The tests show 2-2.5 Gbps per core. With 16-core CPU it can be as much as 32-35 Gbps.

Auto-push module uses unix domain sockets to pass streams to all workers from the one which has accepted the connection. Every worker has its own unix socket to listen.

The directives to control this feature:

  • rtmp_auto_push on|off - toggle auto-push mode, off by default

  • rtmp_auto_push_reconnect timeout - reconnect timeout after worker got killed, default is 100ms

  • rtmp_socket_dir dir - directory where worker unix domain sockets will be created, default it /tmp. Permissions to create files at that location are needed obviously

All the directives should be placed at the root (top) scope (not rtmp{} or whatever).

rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /var/sock;

rtmp {
server {
listen 1935;
application myapp {
live on;

Statistics url does not return overall statistics for all workers but for a single random worker (which accepted the request). That's a task for future.


  1. Hey rarut.
    Thanks a lot for extremly useful module!!!

    I was trying to minimize the delay (despite bandwitch/cpu usage, that's not a problem for now) but I couldn't go lower than 4-5 seconds.

    I and the server have fast connection so it's transfter speed which limits me(buffer is 0.0s).

    I'm not using ffmpeg on server side, my rtmp settings are default (besides allow/deny).
    For publishing I'm using FMLE with H.264(level 3.1, keyframe freq. 1), framerate 15, dimensions 768*576, bitrate 2K (max)
    For playing i'm using rtmpdump + VLC.

    any tips? :)

  2. What kind of delay do you mean? Connection delay before actual video appears? If so then it can be about video keyframe interval. Players usually wait until first keyframe comes in before starting playing video.

  3. Hi! No, actually I ment `how long does it take for viewer to see my broadcast`. I ran VLC to view my stream from the server and counted seconds after some action.

  4. Player usually buffers data. Yo can set buffer time in player settings.

  5. Hi, rarut.
    1. does rtmp_auto_push is only needed when one want to spread the load of one stream. says rtmp-module can use up to two cpu core, when the server have two published stream without rtmp_auto_push on. is this correct?
    2. the number of rtmp module worker is the same as nginx-http worker? and control by worker_processes?

  6. 1. rtmp_auto_push publishes each stream to all workers. You need it for live streaming if you have multiple nginx workers. There's no connection between the number of cpu cores and the number of streams.
    2. yes, nginx-rtmp uses nginx core.