search
HomeOperation and MaintenanceNginxHow to optimize Nginx high concurrency kernel

What is high concurrency

  • The default Linux kernel parameters consider the most common scenarios and are not suitable for web applications that support high concurrent access. server, so you need to modify the Linux kernel parameters, so that nginx can have higher performance; To make adjustments, when nginx is used as a static web content server, a reverse proxy, or a server that provides a compression server, the adjustments to the kernel parameters are different. Here are the most common TCP network parameters that enable nginx to support more concurrent requests. Make simple configurations;

  • These require modifying /etc/sysctl.conf to change the kernel parameters.

  • Configuration method


Configuration detailed analysis

#Indicates that a single process is large The number of handles that can be opened; the

fs.file-max = 999999
# parameter is set to 1, which means that the socket in the time_wait state is allowed to be reused for a new tcp link. This is of great significance to the server because there are always a large number of links in the time_wait state. Exists;

net.ipv4.tcp_tw_reuse = 1

#When keepalive is started, the frequency of tcp sending keepalive messages; the default is 2 hours, setting it to 10 minutes can clean up invalid links faster.

ner.ipv4.tcp_keepalive_time = 600

#When the server actively closes the link, the maximum time the socket remains in the fin_wait_2 state

net.ipv4.tcp_fin_timeout = 30

#This parameter indicates the maximum value of the number of time_wait sockets allowed by the operating system. If it exceeds With this number, the time_wait socket will be cleared immediately and a warning message will be printed.

#This parameter defaults to 180000. Too many time_wait sockets will slow down the web server.

net.ipv4.tcp_max_tw_buckets = 5000

#Define the value range of the local port for udp and tcp links.

net.ipv4.ip_local_port_range = 1024 65000

# Defines the minimum value, default value, and maximum value for tcp to accept cache.

net.ipv4.tcp_rmem = 10240 87380 12582912

#Define the minimum value, default value and maximum value of tcp send cache.

net.ipv4.tcp_wmem = 10240 87380 12582912

#When the network card receives data packets faster than the kernel processing speed, there will be a queue to save these data packets. This parameter represents the maximum value of the queue.

net.core.netdev_max_backlog = 8096

#Indicates that the kernel socket accepts the default size of the buffer area.

net.core.rmem_default = 6291456

# indicates the default size of the kernel socket send buffer.

net.core.wmem_default = 6291456

#Indicates that the kernel socket accepts a larger buffer size.

net.core.rmem_max = 12582912

#Indicates the larger size of the kernel socket send buffer.

net.core.wmem_max = 12582912

Note: The above four configurations need to be comprehensively considered based on business logic and actual hardware costs;

# has nothing to do with performance. Used to solve tcp syn***.

net.ipv4.tcp_syncookies = 1

#This parameter indicates the maximum length of the syn request queue accepted during the TCP three-way handshake establishment phase. The default is 1024. Setting it larger can prevent Linux from being too busy to accept new connections when nginx is busy. Lost client-initiated link request.

net.ipv4.tcp_max_syn_backlog = 8192

#This parameter is used to set and enable timewait fast recycling.

net.ipv4.tcp_tw_recycle = 1

The default value of the option is 128. This parameter is used to adjust the number of TCP connections initiated by the system at the same time. In high-concurrency requests, the default value may cause the link to time out or retransmit, so it needs to be combined with high concurrency. Adjust this value based on the number of requests. The

net.core.somaxconn=262114

# option is used to set the maximum number of tcp sockets in the system that are not associated with any user file handle. If this number is exceeded, the orphan link will be reset immediately and a warning message will be output. This limit indicates that in order to prevent simple dos***, you do not need to rely too much on this limit or even reduce this value. In more cases, increase this value.

net.ipv4.tcp_max_orphans=262114

For ease of use, you can copy it directly below

net.ipv4.tcp_tw_reuse = 1
fs.file-max = 999999
net.ipv4.tcp_fin_timeout = 30
ner.ipv4.tcp_keepalive_time = 600

The above is the detailed content of How to optimize Nginx high concurrency kernel. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Using NGINX Unit: Deploying and Managing ApplicationsUsing NGINX Unit: Deploying and Managing ApplicationsApr 22, 2025 am 12:06 AM

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX vs. Apache: A Comparative Analysis of Web ServersNGINX vs. Apache: A Comparative Analysis of Web ServersApr 21, 2025 am 12:08 AM

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINX Unit's Advantages: Flexibility and PerformanceNGINX Unit's Advantages: Flexibility and PerformanceApr 20, 2025 am 12:07 AM

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX vs. Apache: Performance, Scalability, and EfficiencyNGINX vs. Apache: Performance, Scalability, and EfficiencyApr 19, 2025 am 12:05 AM

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software