Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is worker_processes and worker_connections in Nginx?

Tags:

nginx

People also ask

What is multi accept in Nginx?

multi_accept off – A worker process accepts one new connection at a time (the default). If enabled, a worker process accepts all new connections at once. We recommend keeping the default value ( off ), unless you're sure there's a benefit to changing it.

What is worker connection?

worker_connections – The maximum number of connections that each worker process can handle simultaneously. The default is 512, but most systems have enough resources to support a larger number.

What is the maximum number of connections available in Nginx?

With NGINX, every open connection equates to at least one or sometimes two open files. By setting the maximum number of connections to 4096 , we are essentially defining that every worker can open up to 4096 files.

What is keepalive_timeout in Nginx?

Context: http , server , and location. This directive defines the number of seconds the server will wait before closing a keep-alive connection. The second (optional) parameter is transmitted as the value of the Keep-Alive: timeout= <HTTP response header> .


worker_connections is the number of simultaneous connections; so they are simply stating how to calculate, for example:

  • you are only running 1 process with 512 connections, you will only be able to serve 512 clients.

  • If 2 processes with 512 connections each, you will be able to handle 2x512=1024 clients.

The number of connections is limited by the maximum number of open files (RLIMIT_NOFILE) on your system

nginx has a better, updated description of worker connections.

fyi, the wiki section is considered obsolete (dont ask), now only the main nginx.org/en/docs are preferred...


  • Worker processes:

    • Nginx worker process that handles the incoming request.
    • Set this to worker_process auto; to automatically adjust the number of Nginx worker processes based on available cores.
    • This can go beyond the available cores if you have IO access.
  • Worker connections:

    • Each worker process can open a by default 512 connections.
    • You can change this limit by worker_connections <no>.
    • You can set this to max limit ulimit -n.
    • hence,

    max_clients = worker processes * worker connections


From Nginx's Beginner’s Guide

nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests. nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes. The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically adjusted to the number of available CPU cores