How We Boosted Nginx Performance 50× by Tuning Gzip Settings
This article documents a real‑world Nginx optimization case where adjusting gzip compression levels and switching to static gzip reduced CPU usage dramatically, enabling a 9‑wan QPS load to be handled with only 7% CPU and achieving over a 50‑fold performance gain.
This article records a practical Nginx tuning process that increased overall server performance by about 50 times through step‑by‑step analysis and implementation.
1. Requirement Background
The project needed to display data in multiple rounds, with an estimated peak of 90,000 QPS. As backend engineers we initially prepared the API, hierarchical caching, machine scaling, and maxed out threads, but frequent data updates forced us to generate static files and serve them via CDN.
The architecture is illustrated below:
After each data update, new static files are generated and CDN is refreshed, causing a massive surge of origin requests that could hold up to 90,000 QPS on the application servers.
2. First Load Test
Two data‑center rooms with 40 machines (4 C each) served 25 KB files at 50,000 QPS, pushing CPU to 90 %.
Adding more machines did not solve the bottleneck; CPU remained saturated even after doubling the servers to 80.
We suspected the enabled gzip compression might be consuming CPU.
server {
listen 80;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain application/css text/css application/xml text/javascript application/javascript application/x-javascript;
...
}3. Second Load Test
We reduced the gzip compression level from 6 to 2 to lower CPU load. gzip_comp_level 2; CPU still saturated quickly, but QPS barely reached 90,000, confirming gzip was the main CPU consumer.
4. Understanding Nginx Gzip
Nginx is renowned for high‑performance static serving, yet gzip compression can become a CPU bottleneck. Gzip works by removing redundant characters in static files (HTML, CSS, JS) to reduce bandwidth.
Gzip in Nginx has two modes:
Dynamic compression : The server compresses responses on the fly, consuming CPU for each request.
Static compression : Pre‑compressed .gz files are served directly; if a .gz file is missing, the original file is used.
Static compression requires the ngx_http_gzip_static_module, which is already compiled in the JDos Nginx distribution.
We generated .gz files locally using GZIPOutputStream and enabled static compression in Nginx:
gzip_static on;5. Final Results
With static gzip, 40 machines handled the 90,000 QPS load using only 7 % CPU. Pushing further, CPU grew slowly while network output reached 89 MB/s; QPS climbed to 270,000.
Overall, QPS increased from 50 k to 270 k (≈5×), CPU usage dropped from 90 % to 7 % (≈10×), delivering more than a 50‑fold performance improvement.
6. Conclusion
Static gzip compression provides overwhelming benefits for immutable files, eliminating CPU and bandwidth waste. Dynamic compression remains suitable for API responses that change frequently. This hands‑on experience deepened our understanding of Nginx’s gzip mechanisms and highlighted a valuable optimization path for backend engineers.
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.
JD Cloud Developers
JD Cloud Developers (Developer of JD Technology) is a JD Technology Group platform offering technical sharing and communication for AI, cloud computing, IoT and related developers. It publishes JD product technical information, industry content, and tech event news. Embrace technology and partner with developers to envision the future.
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.
