Rate This Document
Findability
Accuracy
Completeness
Readability

Configuring Kernel Parameters

Purpose

Modify kernel parameters of the operating system to improve server performance.

Procedure

  1. Open the sysctl.conf file.
    1
    vim /etc/sysctl.conf
    
  2. Press i to enter the insert mode, add the following parameters, and save the configuration file:
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_keepalive_time = 60
    net.ipv4.tcp_fin_timeout = 1
    net.ipv4.tcp_max_tw_buckets = 5000
    net.ipv4.ip_local_port_range = 1024    65500
    net.core.somaxconn = 65535
    net.ipv4.tcp_max_syn_backlog = 262144
    net.core.netdev_max_backlog = 262144
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216

    Table 1 describes the kernel parameters.

    Table 1 Kernel parameter description

    Linux Parameter

    Description

    Current Value

    Default Value

    net.ipv4.tcp_tw_reuse

    Specifies whether to reuse TIME-WAIT sockets. 1: allows TIME-WAIT sockets to be used for new TCP connections. 0: disables the use of TIME-WAIT sockets for new TCP connections.

    1

    0

    net.ipv4.tcp_keepalive_time

    Specifies the interval (in seconds), at which a keepalive message is sent. This messages checks whether a TCP connection is valid.

    60

    7200

    net.ipv4.tcp_fin_timeout

    Specifies the maximum duration for the socket to remain in FIN_WAIT_2 state.

    1

    60

    net.ipv4.tcp_max_tw_buckets

    Specifies the maximum number of TIME_WAIT connections. Reducing the number of TIME_WAIT connections can prevent excessive TIME_WAIT connections from occupying network resources and reduce the latency.

    5000

    262144

    net.ipv4.ip_local_port_range

    Specifies the range of the ports that can be used. Increasing the number of available ports can prevent performance dip when ports are occupied by a large number of connections.

    1024 65500

    32768 61000

    net.core.somaxconn

    Specifies the maximum length of the listening queue of an interface. This is a global parameter.

    65535

    128

    net.ipv4.tcp_max_syn_backlog

    Specifies the SYN queue length. More network connections can be supported by increasing the queue length.

    262144

    1024

    net.core.netdev_max_backlog

    Specifies the maximum number of data packets that can be sent to the queue when the packet receive rate at each network port is higher than the data packet processing rate of the kernel.

    262144

    1000

    net.core.rmem_max

    Specifies the maximum read buffer of the system socket.

    16777216

    131071

    net.core.wmem_max

    Specifies the maximum write buffer of the system socket. Increasing the buffer size can prevent buffer overflow caused by a large number of new connections.

    16777216

    131071

  3. Press Esc, type :wq!, and press Enter to save the file and exit.
  4. Run the following command to make the configuration take effect:
    1
    /sbin/sysctl -p