memc_next_upstream
The `memc_next_upstream` directive defines behavior for retrying upstream memcached servers based on specified failure conditions.
Description
The memc_next_upstream directive in the ngx_memc module is used to control how NGINX handles the selection of next upstream memcached servers when a request fails. This is particularly useful in scenarios where a given server may be unresponsive or returning errors, allowing the system to pass requests to alternative memcached servers to enhance availability and reliability. The directive accepts one or more parameters that specify which errors should trigger the failover mechanism, such as timeout, invalid, or error. By listing multiple conditions, administrators can fine-tune their caching strategies to mitigate temporary issues without impacting user experience.
When the defined fail conditions occur, NGINX will try the next server defined in the upstream configuration until a successful response is received or all servers have been tried. This mechanism is critical for maintaining high availability in cached environments, especially when using clustered memcached setups where individual nodes may experience intermittent issues. The configuration of this directive should be aligned with other directives like memc_pass and memc_connect_timeout to effectively manage server interactions and handle fallbacks seamlessly.
Config Example
server {
location /foo {
set $memc_key $arg_key;
memc_pass 127.0.0.1:11211;
memc_next_upstream error timeout;
}
}If no upstream servers are defined, this directive will not have any effect.
Misconfiguring the conditions may lead to unnecessary retries, impacting performance.
Using too many failure conditions may cause long delays in completing requests.