worker_processes

The worker_processes directive sets the number of worker processes in NGINX.

Syntaxworker_processes number | auto;
Default1
Contextmain
Arguments1

Description

The worker_processes directive determines how many worker processes NGINX will create to handle requests. Each worker process can handle multiple connections simultaneously, allowing NGINX to scale efficiently with the number of available CPU cores and the volume of incoming requests. The number of worker processes specified can significantly impact the overall performance of the server, especially under high traffic conditions.

This directive can accept an integer value representing a fixed number of worker processes or the keyword auto, which instructs NGINX to automatically set the number based on the available CPU cores. When set to auto, NGINX will calculate the number of worker processes based on the number of CPU cores detected on the server. It is recommended to set this value according to the hardware and specific application needs to achieve optimal performance.

In practice, when configuring the worker_processes directive, system administrators should monitor the load and performance metrics of their applications to determine an appropriate value. Both undershooting and overshooting the number of worker processes can lead to performance degradation. Careful tuning may be necessary in some environments to match the characteristics of the expected load on the server.

Config Example

worker_processes auto;

Setting worker_processes higher than the number of available CPU cores can lead to context switching and decreased performance.

Using a very low number of worker processes may lead to slow responses under high load because fewer requests will be handled concurrently.

← Back to all directives