Operations 4 min read

Boost Nginx High-Concurrency Performance by Up to 10×: Practical Tuning Guide

This article explains how to unleash Nginx's full potential for high‑concurrency workloads by adjusting worker processes, raising file‑descriptor limits, enlarging TCP connection queues, and persisting sysctl settings, enabling up to ten‑fold throughput improvements in production environments.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Boost Nginx High-Concurrency Performance by Up to 10×: Practical Tuning Guide

Worker Processes

Nginx uses a master+worker multi‑process model; each worker is single‑threaded and can run on a separate CPU core. The default single worker underutilizes multi‑core CPUs. Setting worker_processes auto (or the number of cores) enables parallel request handling and reduces context‑switch overhead. Optionally bind CPU affinity with worker_cpu_affinity auto.

Nginx high concurrency performance optimization
Nginx high concurrency performance optimization

File Descriptor Optimization

In Linux, network connections are file descriptors. Nginx consumes a descriptor for each connection, log file, and backend socket. Insufficient descriptors cause “too many open files” errors. Raise the system limit fs.file-max and the per‑process limit ulimit -n. In Nginx config set worker_rlimit_nofile 100000; and worker_connections 65535; to support high‑concurrency long‑connections and massive static file serving.

File descriptor limits
File descriptor limits

TCP Connection Queue Optimization

When request arrival exceeds worker processing speed, new connections queue. A small queue leads to dropped connections or client timeouts, especially in flash‑sale (秒杀) systems. Increase the Linux kernel backlog with net.core.somaxconn = 65535 to allow more pending connections.

TCP queue settings
TCP queue settings

Production‑Ready System Settings

Rather than using temporary sysctl -w commands, persist the tuned parameters in system configuration files. Example settings:

fs.file-max = 1000000
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

These values together enable Nginx to handle ten times more concurrent requests in production environments.

Production configuration
Production configuration
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Performance tuningTCPLinuxhigh concurrencynginxsysctl
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.