Home >Backend Development >PHP Tutorial >NGINX kernel parameter optimization
The optimization of kernel parameters is mainly the optimization of system kernel parameters for Nginx applications in Linux systems.
An optimization example is given below for reference.
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net. ipv4.tcp_keepalive_time = 30
Add the above kernel parameter values to the /etc/sysctl.conf file, and then execute the following command to make it effective
/sbin/sysctl -p
The above parameters are introduced below:
net .ipv4.tcp_max_tw_buckets is used to set the number of timewait. The default is 180000, here it is changed to 6000.
net.ipv4.ip_local_port_range is used to set the minimum port range allowed to be opened by the system 1024.
net.ipv4.tcp_tw_recycle is used to set the startup timewait speed. Recycle.
net.ipv4.tcp_tw_reuse is used to set up reuse, allowing time-wait sockets to be reused for new tcp connections.
net.ipv4.tcp_syncookies is used to enable syn cookies. When a syn waiting queue appears, cookie processing is enabled
The default value of net.core.somaxconn is 128. The parameter is used to adjust the number of TCP connections initiated by the system at the same time. In highly concurrent requests, the default value may cause connection timeout or retransmission. Therefore, this parameter needs to be adjusted in conjunction with the number of concurrent requests. value.
net.core.netdev_max_backlog represents the maximum number of packets allowed to be sent to the queue when each network interface accepts packets faster than the kernel can process them.
net.ipv4.tcp_max_orphans 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 orphaned connection will be reset immediately and a warning message printed. This limit is to prevent simple DOS attacks. You cannot rely too much on this limit or even artificially reduce this value. In more cases, you should increase this value.
net.ipv4.tcp_max_syn_backlog is used to record the maximum value of connection requests that have not yet received client confirmation information. For systems with 128MB of memory, the default value of the secondary parameter is 1024, and for systems with small memory it is 128. net.ipv4.tcp_synack_retries The value of the parameter determines the number of SYN+ACK packets sent before the kernel gives up the connection. net.ipv4 .tcp_syn_retries represents the number of SYN packets sent before the kernel gives up the connection. Net.ipv4.tcp_fin_timeout determines how long the socket remains in the FIN-WAIT-2 state. The default value is 60 seconds. It is very important to set this value correctly. Sometimes even a web server with a small load will have a large number of dead sockets and risk memory overflow.
net.ipv4.tcp_keepalive_time indicates the frequency of tcp sending keepalive messages when keepalive is started. The default value is 2 (units are hours).
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced NGINX kernel parameter optimization, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.