upstream_fair_shm_size
Sets the size for shared memory in the fair load balancer module for tracking server states.
Description
The upstream_fair_shm_size directive is used to configure the size of shared memory allocated for storing server state information when using the fair load balancer in NGINX. This directive allows the fair load balancer to keep track of server activity such as request counts and failures, facilitating better distribution of traffic to less busy servers. The shared memory segment is crucial for maintaining performance and reliability, especially in environments with high concurrency or varying server workloads.
The parameter specified for upstream_fair_shm_size determines how much memory is allocated. A larger size allows for more extensive tracking of server states, which can be beneficial for applications with many back-end servers or those experiencing varying workloads. When this directive is set, the fair load balancer initializes a shared memory block based on the specified size, enabling it to allocate necessary structures to manage back-end peers efficiently. Depending on the load and the number of requests processed, administrators may need to adjust this directive to optimize NGINX's performance.
The directive should be placed in the http context of the NGINX configuration file, and it is critical that the allocated size matches the needs of the applications running behind the proxy to avoid contention for shared memory resources.
Config Example
http {
upstream my_backend {
fair;
server backend1.example.com;
server backend2.example.com;
}
upstream_fair_shm_size 10m;
}Setting the size too small may lead to insufficient memory for tracking server statuses, causing suboptimal load balancing behavior.
Ensure the memory size is compatible with overall server memory to avoid resource contention.