In heavy traffic environments, Nginx plays a crucial role in handling requests. To make sure that it is operating at peak efficiency, we have several tuning suggestions and handy tips to help you avoid network bottlenecks.
keep_alive
It’s always expensive to create new connections for every new upstream connection. Control your overhead on network CPU costs by enabling keep_alive, which allows you to reuse existing connections. By default, Nginx will terminate the connections of all clients and create new connections.
upstream artifactory { keepalive 100; server artifactory:8081; }
worker_processes
This highly useful directive allows Nginx to simultaneously handle a large number of connections. The optimal value to set for worker_processes depends on many things, such as CPU, HDD, and on load pattern. However, the directive with the auto flag:
worker_processes auto;
will allow it to auto-detect and set the appropriate settings.
Monitor Your Logs
Nginx (or any web server) writes every request to an access log file, which consumes CPU and Disk I/O. Enabling access log buffering is one good option to decrease the write load by retaining your log entries in a buffer and, subsequently, saving them in a single operation, instead of writing each entry individually.
To enable access log buffering, add buffer=size to your access_log directive:
access_log /var/log/nginx/artprod.mycompany-access.log buffer=32k;