accept_mutex_delay
The 'accept_mutex_delay' directive controls the time a worker will wait for the accept mutex to become available before accepting new connections.
Description
The 'accept_mutex_delay' directive in NGINX specifies the delay applied when a worker process tries to accept a new connection but cannot acquire the accept mutex immediately. This mutex is essential for synchronizing access among multiple worker processes to avoid overwhelming the server with rapid connection requests. If a worker is unable to acquire this mutex, it will pause for a duration specified by this directive before attempting to accept connections again, thereby balancing load across workers and enhancing efficiency.
The parameter for 'accept_mutex_delay' is defined in milliseconds, allowing administrators to finely tune the delay based on their server's capacity and expected load. For example, setting 'accept_mutex_delay 500;' allows a worker to wait for up to half a second before trying again. This setting can greatly affect how connections are distributed across multiple worker processes, especially in high-concurrency scenarios. Proper tuning can maximize throughput and reduce latency while minimizing resource contention.
It is important to note that while increasing the delay can improve fairness during heavy loads by allowing other workers to accept connections, it may also lead to fewer accepted connections under low-load conditions, so it needs to be set based on actual traffic patterns.
Config Example
events {
accept_mutex on;
accept_mutex_delay 300;
}For the directive to take effect, accept_mutex must be enabled.
Setting a very high delay can result in lower connection acceptance rates, particularly during low traffic.
Not all operating systems handle mutexes in the same manner, which can affect the behavior of this directive.