nchan_message_buffer_length

Sets the maximum number of messages to retain in the Nchan message buffer.

Syntaxnchan_message_buffer_length number;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The nchan_message_buffer_length directive is used to specify the maximum number of messages that can be kept in the message buffer for each channel managed by the Nchan module. This buffer plays a critical role in the pub/sub mechanism, where messages are sent to subscribers through various transport methods such as WebSocket, long-polling, or SSE. By configuring this directive, administrators can control how much memory is allocated for message storage, which can help optimize resource usage, especially when dealing with high message throughput or a large number of connections.

When the buffer reaches the defined length, the oldest messages in the buffer are discarded to make room for new messages. This behavior prevents the server from consuming excessive memory and also allows for a more predictable handling of messages. The directive can be applied at multiple configuration contexts such as http, server, or location, thereby giving flexibility in how its parameters can be scoped based on the application’s needs. For instance, different channels may have different message retention strategies based on their use cases and expected traffic patterns.

Config Example

location /pubsub {
    nchan_message_buffer_length 100;
}

Setting a low buffer length may lead to message loss if subscribers cannot keep up with the publishing speed.

Ensure that this directive is set appropriately in all required contexts, as it can be defined at http, server, or location levels.

← Back to all directives