nchan_shared_memory_size

The `nchan_shared_memory_size` directive configures the amount of shared memory allocated for Nchan's message storage.

Syntaxnchan_shared_memory_size size;
Defaultnone
Contexthttp
Arguments1

Description

The nchan_shared_memory_size directive is crucial for optimizing the pub/sub performance of Nchan, a scalable messaging solution built as a module for NGINX. This directive defines the size of the shared memory space that Nchan can use to store messages for channels. The allocation of shared memory allows for quick access and efficient handling of messages that are published and subscribed to in real time. When clients connect to Nchan channels, this memory is utilized to manage the message buffers and subscriber states, ensuring low latency and high throughput.

The parameter for this directive is a size in bytes, expressed in common suffixes such as k, m, or g for kilobytes, megabytes, and gigabytes, respectively. When a message is published to a channel, it is stored in this shared memory, benefiting from NGINX's asynchronous capabilities, which effectively handle potentially thousands of concurrent connections. If the specified size is exhausted, older messages may be discarded according to the policy set, which could affect the delivery of messages to subscribers if not managed properly. Thus, it is essential to tune this parameter based on the expected workload, number of channels, and message sizes to prevent message loss and performance degradation.

Config Example

http {
    nchan_shared_memory_size 10m;
    # Additional configurations may follow...
}

Setting the shared memory size too low may lead to message loss due to overflow.

Shared memory allocations are fixed at runtime; changes require NGINX to be reloaded for them to take effect.

If multiple Nginx instances are used with Nchan, ensure each has an appropriately configured shared memory size using the same consideration for overall load.

← Back to all directives