NGINX Worker Processes and Connections

I am a DevOps Consultant. 3 years experience with Cloud technologies. 9 years total IT experience in the Linux, Networking and Data Visualization domains. Love listening to music and playing older PC games.
Search for a command to run...

I am a DevOps Consultant. 3 years experience with Cloud technologies. 9 years total IT experience in the Linux, Networking and Data Visualization domains. Love listening to music and playing older PC games.
No comments yet. Be the first to comment.
In this basic level series, I will post best practices to configure the NGINX web server using Linux based instances.
Introduction In the world of web servers and content delivery, Nginx has emerged as one of the most popular and efficient solutions. One of the key features that make Nginx stand out is its powerful buffering capabilities. In this article, we will ex...
Hi readers, There are times when we make huge decisions in our lives. These may not be easy to make due to several reasons. Like the decision I made to quit DevOps completely. You may feel that I quit suddenly, but I took this decision years ago. It ...

Objectives Target the code at: https://github.com/melvincv/java-basic-practice-app Switch to main-v2 branch. Build the code using GitHub Actions. Deploy the code on two AWS EC2 servers. (independently) Implement approval process for deployment o...

with Sonarqube, Ansible and Blue / Green deployment

Jenkins Install Controller and Agent The controller is the main Jenkins instance that will co-ordinate the connections and tooling for the agents. Agents are the workhorse instances used to run jobs and pipelines. It can have various tools and unique...

Docker, Kubernetes and GitOps

When we start the NGINX service, we get a master process which we can view using systemctl. This master process then spawns worker processes that are used to serve requests. The default is one worker process.
We can change the no. of worker processes using the worker_processes directive. But more workers do not necessarily mean more performance. Each NGINX process will serve as many requests as the hardware can support.
There are instances where there are benefits in increasing the no. of worker processes. On a multicore CPU, for example. A single NGINX process can only work on one core of a CPU. So say, we have an 8-core CPU. The optimal no. of worker processes would be 8. Do not run more than one process on one core.
You may check the no. of CPU cores in a Linux server using:
nproc
lscpu
Setting the worker_processes directive to auto will auto-increase the no. of processes to match the no. of cores on your server.
worker_processes auto;
events {
worker_connections 1024;
}
The worker_connections directive specifies the maximum number of connections that each worker process can handle. The default value is 512. However, you may want to increase the value of worker_connections if your server is handling a lot of traffic.
For example, if you have a server with 4 GB of RAM, you might want to set worker_connections to 1024. This will allow each worker process to handle up to 1024 connections, which can help to improve performance.
It is important to note that the total number of connections that NGINX can handle is limited by the number of open file descriptors that the system allows. You can check the maximum number of open file descriptors with the following command:
ulimit -n
1024
If the number of open file descriptors is lower than the value of worker_connections, you will need to increase the value of ulimit.
Total no. of requests that can be served = worker processes * worker connections
This is very important for the performance optimization of NGINX.
By understanding the worker processes and number of connections settings in NGINX, you can optimize your server's performance and ensure that it can handle a large number of concurrent connections.