Operations 7 min read

How to Tune Nginx for 100k+ Concurrent Connections: Step‑by‑Step Guide

This guide explains how to identify Nginx bottlenecks, apply a series of configuration and kernel tweaks—including worker processes, event model, connection limits, gzip, proxy timeouts, and sysctl settings—and then validate the improvements with Apache ab load testing to achieve up to 100 000 concurrent requests.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
How to Tune Nginx for 100k+ Concurrent Connections: Step‑by‑Step Guide

Optimization Overview

A typical Nginx Linux server can handle 500,000–600,000 requests per second; with proper tuning it can reach a stable 904,000 req/s, dramatically increasing concurrent access.

Optimization Steps

Identify the Nginx bottleneck.

Apply configuration tweaks.

Retest with a load‑testing tool.

Identify Bottleneck

Use Apache ab to generate load, e.g. ab -n 200000 -c 5000 http://localhost:8080/index.html, and check the status page http://127.0.0.1/status for connections, waiting and other metrics.

Configuration Tweaks

Worker processes and CPU affinity

worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

Event model (epoll for CentOS)

events {
    worker_connections 10240;
    use epoll;
}

Worker connections worker_connections 10240; Maximum open files per process

worker_rlimit_nofile 65535;  # usually matches ulimit -n

Keepalive timeout keepalive_timeout 60; Gzip compression

gzip on;
gzip_min_length 1k;
gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/css text/xml application/javascript;
gzip_vary on;

Proxy timeout settings

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;

Efficient file transfer

sendfile on;
 tcp_nopush on;

Kernel Parameters (sysctl)

net.core.somaxconn = 262144
net.core.somaxconn = 4096
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_max_orphans = 262144

Set the maximum number of open files for the system: ulimit -n 30000 After applying these settings, run the ab test again to verify the performance gain and adjust parameters as needed.

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.

performanceoptimizationlinuxhigh concurrencyLoad TestingNginxsysctl
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

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.