scgi_cache_lock_age

The `scgi_cache_lock_age` directive controls the duration for which a request will acquire a lock on the cache entry for SCGI responses.

Syntaxscgi_cache_lock_age time;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The scgi_cache_lock_age directive in NGINX is an important parameter within the context of caching SCGI responses. When a request to an SCGI backend is made and a cache miss occurs, NGINX will attempt to cache the response of that request for subsequent identical requests. To prevent multiple processes from create duplicate SCGI requests while the original request is still being processed, this directive specifies how long (in seconds) a cache lock should be held until the response is fetched and cached. By setting this age, you effectively control the concurrency of requests for the same cache entry, ensuring that only one request is processed for a specific cache entry until a response is available.

The typical use case for scgi_cache_lock_age is to avoid the thundering herd problem, where multiple server requests cause a backend service to become overloaded with requests. By locking the cache entry against multiple simultaneous requests until the first one completes, NGINX helps to mitigate potential load issues and improves overall response efficiency. The parameter accepts a duration specified in seconds, and its value should be carefully selected based on server load and expected request patterns to optimize performance while effectively managing resource usage.

Config Example

location /api {
    scgi_pass backend;
    scgi_cache my_cache;
    scgi_cache_lock on;
    scgi_cache_lock_age 10s;
}

If scgi_cache_lock is turned off, the scgi_cache_lock_age directive will have no effect.

This directive should be used in conjunction with caching directives to be effective.

Misconfiguration can lead to unnecessary waits for other requests to complete before responding.

← Back to all directives