multi_accept

The multi_accept directive allows a worker process to accept multiple connections simultaneously from a listening socket.

Syntaxmulti_accept on | off;
Defaultoff
Contextevents
Argumentsflag

Description

The multi_accept directive in NGINX is used to optimize the connection handling process by allowing a worker process to accept multiple new connections at once instead of a single connection at a time. When this directive is enabled, the worker process can effectively increase its throughput by reducing the overhead associated with context switching and the latency of individual connection handling.

This directive can be set to either on or off. When set to on, it instructs the worker processes to accept as many new connections as the operating system socket layer allows. This behavior is particularly beneficial in high-load scenarios where many simultaneous connections are expected. On the other hand, when multi_accept is set to off, the default behavior is to accept only one connection at a time. This can lead to higher latency for incoming connections, as subsequent connections must wait until the worker is free to process them.

It's important to consider that enabling multi_accept does not guarantee performance improvements in every situation. The benefits largely depend on the underlying operating system's handling of socket operations and the specific load conditions on the server. Server admins should monitor their server's performance to determine whether enabling this directive yields the intended performance outcomes.

Config Example

events {
    multi_accept on;
    worker_connections 1024;
}

Enabling multi_accept may lead to increased CPU usage and context switching, particularly under heavy loads.

On some systems, enabling this feature may not yield performance improvements if the underlying OS doesn't handle the increased acceptance optimally.

← Back to all directives