memc_upstream_max_fails

Sets the maximum number of failed attempts to reach a memcached server before it is marked as down.

Syntaxmemc_upstream_max_fails number;
Default1
Contexthttp, server, location
Arguments1

Description

The memc_upstream_max_fails directive controls the tolerance level for failed connection attempts to a memcached server when NGINX is configured to use an upstream memcached module. By specifying an integer value as its argument, you define how many consecutive failed connection attempts are allowed before the server is considered down. If this limit is reached, NGINX will stop sending requests to the failed server until it has successfully reconnected a specified number of times, as controlled by memc_upstream_fail_timeout.<br><br>Using this directive is essential for maintaining high availability in your application. If the number of allowed failures is set too high, it could lead to extensive delays in request handling due to multiple failures. Conversely, setting it too low might cause unnecessary server downtimes, especially if transient network issues occur. The optimal setting often requires testing and tuning according to the specifics of your infrastructure and application behavior.

Config Example

location /foo {
    set $memc_key $arg_key;
    memc_pass 127.0.0.1:11211;
    memc_upstream_max_fails 3;
}

Remember that increasing the number of max fails can cause longer downtimes of the upstream server if it is genuinely down, impacting overall application performance.

Make sure to balance this value with memc_upstream_fail_timeout to control how quickly the server is retried after being marked as down.

← Back to all directives