Tuning OS Parameters
Modify some parameter settings at the operating system layer to improve server performance.
Method
Modify the parameters based on Table 1.
Type |
Parameter |
Description |
Suggestion |
|---|---|---|---|
Network parameters |
net.core.somaxconn |
Maximum length of the socket listening queue. Increase the value if connections are frequently established. |
Default value: 128; recommended value: 2048. |
net.core.netdev_max_backlog |
Length of the buffer queue processed by the protocol stack. If the value is too small, packet loss may occur. |
Recommended value: 10000. |
|
net.core.rmem_default |
Default length of the receiving buffer queue. |
Recommended value: 16777216. |
|
net.core.wmem_default |
Default length of the sending buffer queue. |
Recommended value: 16777216. |
|
net.core.rmem_max |
Maximum length of the receiving buffer queue. |
Recommended value: 16777216. |
|
net.core.wmem_max |
Maximum length of the sending buffer queue. |
Recommended value: 16777216. |
|
net.ipv4.ip_local_port_range |
Local TCP/UDP port range. The local end uses a port in this range to initiate a connection with a remote end. |
Recommended value: 3500 to 65535. |
|
net.ipv4.tcp_rmem |
Size of the socket receiving buffer including the minimum value, default value, and maximum value. |
Recommended minimum value, default value, and maximum value are 4096, 87380, and 16777216, respectively. |
|
net.ipv4.tcp_wmem |
Size of the socket sending buffer including the minimum value, default value, and maximum value. |
Recommended minimum value, default value, and maximum value are 4096, 65536, and 16777216, respectively. |
|
net.ipv4.tcp_max_syn_backlog |
Number of connections in the SYN_RECVD state. |
Recommended value: 16384. |
|
net.ipv4.tcp_fin_timeout |
Duration of the FIN-WAIT-2 state after the socket is disconnected. |
Recommended value: 15. |
|
net.ipv4.tcp_tw_reuse |
Reuse the socket in the TIMEWAIT state. |
Recommended value: 1. |
|
net.ipv4.tcp_slow_start_after_idle |
Disable slow start of TCP connections from the Idle state to reduce network delay. |
Recommended value: 0. |
|
Virtual memory configuration |
vm.swappiness |
Use physical memory preferentially. |
Recommended value: 0. |
vm.max_map_count |
Number of virtual memory areas that a process can have. |
Recommended value: 655360. |
|
AIO configuration |
fs.aio-max-nr |
Number of asynchronous I/O requests. |
Recommended value: 1048576. |
Viewing and Modifying OS Parameters
Modify the OS kernel parameters because these parameters are important to the system performance and stability. You are advised to operate under the guidance of an experienced system administrator.
View and modify the system parameters in Table 1 in either of the following ways:
- The following commands are used to temporarily change parameter values. The parameters will be restored to default after the OS is restarted.For example, run the following command to view the value of net.core.somaxconn:
sysctl net.core.somaxconn
Run the following command to change the value of net.core.somaxconn:sysctl -w net.core.somaxconn=NEW_VALUE
- To permanently change parameter values, for example, the value of net.core.somaxconn, modify the /etc/sysctl.conf configuration file and make the modification take effect:
- Open the /etc/sysctl.conf file.
vi /etc/sysctl.conf
- Press i to enter the insert mode and add the following content to the /etc/sysctl.conf file:
net.core.somaxconn=NEW_VALUE
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Run the command for the modification to take effect:
sysctl -p
- Open the /etc/sysctl.conf file.