nginx,

Improve Nginx performance with worker_processes

Jul 12, 2023 · 1 min read · Post a comment

If we want to know how many connections could be handled by Nginx the basic formula is max_clients = worker_processes * worker_connections. So, here’s a breakdown.

Prerequisites

  • Nginx

Solution

worker_processes are single-threaded process which value is usually determined by number of CPU cores. Setting its value to auto is somehow considered as a best practice.

worker_connections on the other side are representing the number of simultaneous connections. Default value of 512. However, you could update this limitation in the main nginx.conf file under worker_connections <no_of_conn>. The maximum value which should be confirmed first and then set by running ulimit -n (maximum number of open file descriptors allowed for a user or a process. A file descriptor is a unique ID used by the OS to access files, devices, or other resources).

So, with two CPU cores and 512 connections you would have max_connections = 2 * 512 = 1024.

Still, from a process and threads perspective you could think of it as:

  • worker_process = OS process
  • worker_connections = number of threads

Conclusion

In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.