nchan_redis_subscribe_weights

The 'nchan_redis_subscribe_weights' directive allows you to specify weight assignments for Redis subscribers in your NGINX configuration, optimizing load balancing among multiple subscribers.

Syntaxnchan_redis_subscribe_weights channel_id weight;
Defaultnone
Contextupstream
Arguments2

Description

The 'nchan_redis_subscribe_weights' directive is used in the context of 'upstream' blocks to define the distribution of traffic among Redis-backed subscribers in a pub/sub configuration. This directive takes two parameters: the channel ID and the weight. The weight is an integer value that determines how much of the average load is allocated to each Redis subscriber; higher weights grant greater load priority. This allows for finer control over message delivery, especially when different subscribers have varying capacities to handle incoming messages.

By utilizing 'nchan_redis_subscribe_weights', you can achieve a more balanced distribution of message processing, thereby enhancing the performance and scalability of your application. The directive is especially useful in setups where subscribers might have different performance characteristics or when the goal is to favor certain subscribers over others. When a message is published to a channel, NGINX evaluates the weights and sends the message to the selected subscribers based on their weights, effectively optimizing the overall load across the subscribed channels.

This configuration becomes particularly valuable in scenarios involving multiple Redis instances or high-volume message broadcasting. By adjusting the weights according to each subscriber's capabilities, you can prevent overload on any single subscriber and ensure that message processing remains efficient as system demands fluctuate.

Config Example

upstream backend {
    nchan_redis_subscribe_weights my_channel 10;
    nchan_redis_subscribe_weights another_channel 5;
}

Ensure that weights are specified as integers and reflect actual subscriber capabilities.

Misconfiguration of weights might lead to uneven message distribution.

← Back to all directives