NGINX excels in network applications because of its unique design. Many network or application servers are mostly simple frameworks based on threads or processes. NGINX stands out for its mature event-driven framework, which can handle thousands of concurrent connections on modern hardware.
The NGINX Internals infographic starts at the top of the process framework and works its way down to reveal how NGINX handles multiple connections within a single process, and further explores how it works.
Scenario Setup — NGINX Process Model
To better understand this design pattern, we need to understand how NGINX works. NGINX has a main thread to handle privileged operations such as reading configuration files and port binding, as well as a set of working processes and auxiliary processes.
1 2 3 4 5 6 7 8 9 10 11 |
# service nginx restart Restarting nginx # ps ef forest | grep nginx root 32475 1 0 13:36 ? 00:00:00 nginx: master process /usr/ sbin/nginx c /</etc/nginx/nginx.conf nginx 32476 32475 0 13:36 ? 00:00:00 _ nginx: worker <span style="fontsize:inherit !important;fontfamily:inherit;lineheight:inherit !important;font�� Accept connections, handle network communication (with new configuration environment). Loading a process will cause a small CPU and memory spike, but the overhead is negligible compared to the resources loaded from an active connection. The configuration file can be reloaded many times per second. NGINX worker processes that generate many waits for connections to close are generally problematic, but if they are, they can be resolved quickly.
NGINX Binary Upgrades for Ultimate High Availability You can upgrade files online without any loss of connection, service downtime or interruption.
The binary file upgrade process is similar to elegant configuration file overloading; the new NGINX main process runs parallel to the original main process and shares the listening socket. Both processes are active, handling their respective network communications. You can notify the original master process and its workers to exit gracefully. For a detailed description of the process, see NGINX Control
Final remarks
|