Master Nginx Performance: 5 Key Settings to Boost Your Backend
This guide explains five essential Nginx configuration parameters—worker_processes, worker_connections, keepalive_timeout, sendfile/tcp_nopush/tcp_nodelay, and client_max_body_size—detailing their meanings, optimization recommendations, and practical considerations for high‑performance backend services.
Nginx is a core component of large‑scale architectures; understanding its performance bottlenecks is crucial for backend engineers.
1. worker_processes
Defines the number of worker processes Nginx starts, usually matching the number of CPU cores. Optimization tip: set it to the physical or logical CPU core count (e.g., auto) to fully utilize multi‑core parallelism and avoid excessive context‑switch overhead. Adjust for blocking backend modules or high I/O workloads as needed.
2. worker_connections
Specifies the maximum number of simultaneous connections each worker can handle. Optimization tip: calculate a reasonable value based on concurrency needs and the file‑descriptor limit: worker_processes × worker_connections. Increase when using keep‑alive to support persistent connections. Ensure the OS ulimit -n limit is raised accordingly.
3. keepalive_timeout
Controls the timeout for idle persistent (keep‑alive) connections. Optimization tip: for latency‑sensitive, high‑reuse scenarios, extend the timeout (seconds to tens of seconds) to reduce TCP handshake overhead; for massive short‑lived requests, shorten it to free resources. Beware that long keep‑alive periods can consume connection slots and reduce concurrency.
4. sendfile, tcp_nopush, tcp_nodelay
These switches affect I/O and TCP performance. Optimization tip: enable sendfile and tcp_nopush when serving large static files to minimize kernel copies and packet count. Enable tcp_nodelay for low‑latency interactions (small responses, real‑time requirements). Test different combinations under load to find the best configuration.
5. client_max_body_size
Limits the maximum size of a client request body and influences buffering strategy. Optimization tip: set this value according to the maximum upload size your application permits, and adjust client_body_buffer_size to balance memory and disk usage (small buffers may cause large uploads to be written to temporary files). Monitor temporary directory I/O and space when handling frequent uploads.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
