Nginx plays a crucial role in handling requests when it comes to heavy traffic environment. We have multiple tune tips and items in order to avoid any network bottlenecks when Nginx is involved. There are multiple things to tune here, however, we are covering some crucial things.
Keep it Alive! keep_alive:
It is always expensive to create a new connection for every new upstream connection hence enabling the keep_alive will allow us to re-use the existing connections. The default behavior Nginx is to terminate the connections of all clients and create new connections. Hence by enabling keep_alive we are reducing the overhead on network and CPU by just using the existing connections.
Make it work! with worker_processes:
worker_processes is one of the useful directives that allows handling a large number of simultaneous connections. The optimal value to set for worker_processes depends on many things like CPU, HDD or even on load pattern. However, enabling with the auto flag will allow us to auto-detect the appropriate settings
Watch the Logging:
Nginx (or any web server) writes every request into Access log file which in term consumes both CPU and Disk I/O. Enabling access log buffering is one good option to decrease the write load. What happens when we enable Access logs buffering is instead of writing each entry every time Nginx will keep them in a buffer and save them in one go in a single operation.
To enable access log buffering all we need to do is to add buffer=size to the access_log directive
access_log /var/log/nginx/artprod.mycompany-access.log buffer=32k;