push_stream_subscriber_connection_ttl
Sets the time-to-live for subscriber connections in the NGINX Push Stream module.
Description
The push_stream_subscriber_connection_ttl directive configures the duration for which a subscriber connection remains active without any incoming activity in a streaming context. This is crucial for managing resources on the server as it helps in keeping unnecessary connections from lingering indefinitely. The value provided defines the time period (in seconds) after which idle connections will be terminated. By implementing a time-to-live mechanism, it ensures that subscribers that are no longer active are cleaned up efficiently, freeing resources for active users.
When configuring this directive, you can specify it in http, server, or location contexts. This flexibility allows for granular control over how long connections stay alive based on the use case of different endpoints. However, the actual timeout for connections may still be influenced by other factors such as client-side settings or server resource availability, so it’s essential to monitor how this interacts with the overall system design.
Using a short TTL can help in reducing resource consumption on the server but may result in more frequent disconnects for users who are temporarily inactive. Conversely, a longer TTL can provide a better experience for users who may take longer to respond but at the cost of higher resource usage. In practice, administrators should balance these considerations based on the expected usage patterns of their streaming application and the server capabilities.
Config Example
http {
push_stream_subscriber_connection_ttl 30;
server {
location /sub {
push_stream_subscriber;
push_stream_channels_path $arg_id;
}
}
}Not setting this directive may lead to excessive idle connections, consuming server resources.
Values set too low may frustrate users experiencing temporary connectivity interruptions.