Archive for April, 2012

NGINX RTMP broadcast optimizations

Profiling has shown the slowest part of the module is audio/video broadcasting. That was pretty obvious even before profiling but now I’ve got the numbers. To optimize the bottleneck output buffering model should have been slightly modified. Until now each output chain buffer (chunk) had it’s own reference counter. This approach suffers from a problem of re-zipping the chain (re-creating chain links) for each client which required additional per-client chain link allocations.

The new approach is much simpler than before. Each client has fixed-size output queue of chain references. Both buffer and chain links are never changed since creation. The refcounter is now associated with the whole chain and stored in -1 byte of chain link.

The work has been committed to optsend branch. It will be merged into master branch shortly.


Leave a comment

More features in NGINX RTMP

The last updates in include
  • Deferred connection close
  • Relative timing
  • Advanced stream recording

Deferred connection close has greatly simplified event handlers and made it possible to implement complex handlers in future without stability loss.

Relative timing is now implemented in module. Previously all the chunks generated had fmt=0 which means the had absolute timestamps. This was great from the point of audio/video synchronization but some versions of flash plugin failed to work with that. Besides zero-fmt chunks are the biggest among all chunk types. That lead to overhead in transmitted data size. Now relative timing is the default behavior (the old behavior is still possible with ‘abstime on’ directive). Currently fmt=0 chunk is the first in stream with succeeding fmt=1/3 chunks. That’s exactly what RTMP spec advises. The problem with flash plugins is now solved.

More stream recording features are introduced in the most recent version of module:

  • record [off|all|audio|video|keyframes]*; # specify what kind of data should be recorded, can be mixed
  • record_suffix SUFFIX; # default is .flv
  • record_max_size SIZE; # max flv size
  • record_max_frames NFRAMES; # max number of frames to record
  • record_interval TIME; # re-record flv each TIME sec

Leave a comment