idle_streams
The 'idle_streams' directive in the NGINX RTMP module maintains stream inactivity for a defined duration before automatically closing the stream.
Description
The 'idle_streams' directive, when set, allows administrators to define a duration that a stream can be inactive before it is considered idle. Once a stream has been inactive for the specified duration, NGINX will automatically terminate the stream to conserve resources. This is particularly useful in live streaming scenarios where maintaining open but inactive connections can lead to unnecessary resource consumption.
The parameter for this directive is a time value, typically in milliseconds. By specifying a suitable timeout value, you can control how long the server will wait before deciding that a stream has become idle. This directive is especially important in scenarios with concurrent streams, as it helps to reduce the footprint of unused resources and ensures better management of active streams. If this directive is not configured, the server may hold on to inactive streams longer than desired, potentially impacting the performance of active streams and other services.
Configuration of the 'idle_streams' directive should take into account the expected activity of your streams. In a live broadcast situation, a higher timeout may be appropriate, while in other cases, frequent connections and disconnections (like in a server handling varied requests) may warrant a lower timeout to minimize latency and resource usage.
Config Example
rtmp {
server {
application live {
live on;
idle_streams 30000; # 30 seconds
}
}
}If 'idle_streams' is set too low, active users may have their connections closed prematurely.
Make sure your application logic accounts for streams being closed due to idleness; otherwise, users may experience unexpected disconnections.