Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Nginx10m+ High concurrency Kernel Optimization

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you the Nginx 10m + high concurrency kernel optimization example analysis, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

What is high concurrency?

The default Linux kernel parameters are considered to be the most common scenario, which is not suitable for Web servers that support high concurrent access, so you need to modify the Linux kernel parameters so that Nginx has higher performance;

When optimizing the kernel, there are many things that can be done, but we usually adjust it according to the business characteristics. When Nginx is used as a static web content server, a reverse proxy or a server that provides a compressed server, the adjustment of kernel parameters is different. Here is a simple configuration for the most common TCP network parameters that enable Nginx to support more concurrent requests.

These require modification of/etc/sysctl.conf to change kernel parameters.

configuration method

Configuration Details

#indicates the number of handles that a single process can open;

fs.file-max = 999999

#parameter is set to 1, which allows socket in TIME_WAIT state to be reused for new TCP links, which is significant for servers because there are always a large number of links in TIME_WAIT state;

net.ipv4.tcp_tw_reuse = 1

#How often TCP sends keepalive messages when keepalive starts; default is 2 hours, set it to 10 minutes for faster cleanup of invalid links.

ner.ipv4.tcp_keepalive_time = 600

#socket stays in FIN_WAIT_2 state longer when server actively closes link

net.ipv4.tcp_fin_timeout = 30

#This parameter indicates the maximum number of TIME_WAIT sockets allowed by the operating system. If this number is exceeded, 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

#Defines the range of local port values for UDP and TCP links.

net.ipv4.ip_local_port_range = 1024 65000

#defines minimum, default, and larger values for TCP accept cache.

net.ipv4.tcp_rmem = 10240 87380 12582912

#Defines minimum, default, and larger values for TCP send cache.

net.ipv4.tcp_wmem = 10240 87380 12582912

#When the NIC receives packets faster than the kernel processes them, a queue holds them. This parameter indicates the larger value of the queue.

net.core.netdev_max_backlog = 8096

#Indicates the default size of the kernel socket accept buffer.

net.core.rmem_default = 6291456

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

net.core.wmem_default = 6291456

#Indicates a larger kernel socket accept buffer size.

net.core.rmem_max = 12582912

#indicates a larger kernel socket send buffer size.

net.core.wmem_max = 12582912

Note: The above four configurations need to be considered comprehensively according to the business logic and actual hardware cost;

It has nothing to do with performance. SYN*** used to resolve TCP.

net.ipv4.tcp_syncookies = 1

#This parameter indicates that the SYN request queue length accepted during the TCP three-way handshake establishment phase is large. By default, it is 1024. If it is set larger, Linux will not lose the link request initiated by the client when Nginx is too busy to accept the new connection.

net.ipv4.tcp_max_syn_backlog = 8192

#This parameter is used to set enable timewait for quick recovery.

net.ipv4.tcp_tw_recycle = 1

The default value of this option is 128. This parameter is used to adjust the number of TCP connections initiated simultaneously by the system. In high concurrent requests, the default value may cause link timeout or retransmission. Therefore, this value needs to be adjusted in combination with high concurrent requests.

net.core.somaxconn=262114

The #option sets the maximum number of TCP sockets in the system that are not associated with any one user file handle. If this number is exceeded, the orphaned link is immediately reset and a warning message is output. This limit indicates that in order to prevent simple DOS***, do not rely too much on this limit or even think of reducing this value, more often than not increase this value.

net.ipv4.tcp_max_orphans=262114

For ease of use, the bottom can be copied directly

net.ipv4.tcp_tw_reuse = 1fs.file-max = 99999net.ipv4.tcp_fin_timeout = 30ner.ipv4.tcp_keepalive_time = 600 above is "Nginx10m+ high concurrency kernel optimization example analysis" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report