Linux TCPIP kernel parameter optimization

Source: Internet
Author: User

/proc/sys/net Directory

All TCP/IP parameters are located in the/proc/sys/net directory (note that modifications to the contents of the/proc/sys/net directory are temporary and any modifications are lost after the system restarts), such as the following important parameters:

parameters (Path + files)

Describe

Default value

Optimized values

/proc/sys/net/core/rmem_default

The default TCP data Receive window size (in bytes).

229376

256960

/proc/sys/net/core/rmem_max

The largest TCP data Receive window (bytes).

131071

513920

/proc/sys/net/core/wmem_default

The default TCP data Send window Size (in bytes).

229376

256960

/proc/sys/net/core/wmem_max

The largest TCP data Send window (bytes).

131071

513920

/proc/sys/net/core/netdev_max_backlog

The maximum number of packets that are allowed to be sent to a queue when each network interface receives a packet at a rate that is faster than the rate at which the kernel processes these packets.

1000

2000

/proc/sys/net/core/somaxconn

Defines the length of the maximum listening queue for each port in the system, which is a global parameter.

128

2048

/proc/sys/net/core/optmem_max

Represents the size of the maximum buffer allowed for each socket.

20480

81920

/proc/sys/net/ipv4/tcp_mem

Determine how the TCP stack should reflect memory usage, and each value is in a memory page (usually 4KB). The first value is the lower limit for memory usage, and the second value is the upper limit of the applied pressure that the memory pressure pattern begins to use for the buffer, and the third value is the upper limit for memory usage. At this level, messages can be discarded, thereby reducing the use of memory. For larger BDP, these values can be increased (note that the units are in memory pages and not bytes).

94011 125351 188022

131072 262144 524288

/proc/sys/net/ipv4/tcp_rmem

Defines the memory used by the socket for automatic tuning. The first value is the minimum number of bytes allocated for the socket receive buffer, the second value is the default value (the value is overwritten by Rmem_default), and the buffer can grow to this value if the system load is not heavy; the third value is the maximum number of bytes in the Receive buffer space (the value is Rmem_ Max overwrite).

4096 87380 4011232

8760 256960 4088000

/proc/sys/net/ipv4/tcp_wmem

Defines the memory used by the socket for automatic tuning. The first value is the minimum number of bytes allocated for the socket send buffer, the second value is the default value (the value is overwritten by Wmem_default), and the buffer can grow to this value if the system load is not heavy; the third value is the maximum number of bytes in the Send buffer space (this value is Wmem_ Max overwrite).

4096 16384 4011232

8760 256960 4088000

/proc/sys/net/ipv4/tcp_keepalive_time

The interval of time (in seconds) that TCP sends keepalive probe messages to confirm that the TCP connection is valid.

7200

1800

/proc/sys/net/ipv4/tcp_keepalive_intvl

When the probe message is not responding, the time interval (in seconds) for the message to be re-sent.

75

30

/proc/sys/net/ipv4/tcp_keepalive_probes

The maximum number of KeepAlive probe messages sent before the TCP connection is determined to fail.

9

3

/proc/sys/net/ipv4/tcp_sack

Enable selective answer (1 for enable), improve performance by selectively answering packets received by a random order, let the sender send only the missing segment, (for WAN communication) This option should be enabled, but will increase CPU usage.

1

1

/proc/sys/net/ipv4/tcp_fack

Enabling the forwarding answer enables selective response (SACK) to reduce congestion, which should also be enabled.

1

1

/proc/sys/net/ipv4/tcp_timestamps

The TCP timestamp (which increases by 12 bytes in the TCP header) enables the calculation of RTT to be enabled in a more precise way with a specific gravity timeout (refer to RFC 1323), and this option should be enabled for better performance.

1

1

/proc/sys/net/ipv4/tcp_window_scaling

enabling window scaling defined by RFC 1323, to support TCP windows exceeding 64KB, must be enabled (1 for Enable), and TCP Windows will take effect only when both sides of the 1GB,TCP connection are enabled.

1

1

/proc/sys/net/ipv4/tcp_syncookies

Indicates whether the TCP synchronization label (Syncookie) is turned on, the kernel must have the Config_syn_cookies key turned on to compile, and the synchronization label prevents a socket from overloading when there are too many attempts to connect.

1

1

/proc/sys/net/ipv4/tcp_tw_reuse

Indicates whether to allow sockets (time-wait ports) in the time-wait state to be used for new TCP connections.

0

1

/proc/sys/net/ipv4/tcp_tw_recycle

Time-wait sockets can be recycled more quickly.

0

1

/proc/sys/net/ipv4/tcp_fin_timeout

For the socket disconnected on this side, TCP remains in the Fin-wait-2 state for the time (in seconds). The other person may be disconnected or have not ended the connection or the unpredictable process has died.

60

30

/proc/sys/net/ipv4/ip_local_port_range

Represents the local port number that the TCP/UDP protocol allows to use

32768 61000

1024 65000

/proc/sys/net/ipv4/tcp_max_syn_backlog

The maximum number that can be saved in the queue for connection requests that have not yet been confirmed by the other. If the server is overloaded frequently, try increasing this number.

2048

2048

/proc/sys/net/ipv4/tcp_low_latency

This option should be disabled if the TCP/IP stack is allowed to accommodate low latency under high throughput conditions.

0

/proc/sys/net/ipv4/tcp_westwood

Enables the sender-side congestion control algorithm, which maintains the evaluation of throughput and attempts to optimize the overall utilization of bandwidth, which should be enabled for WAN traffic.

0

/proc/sys/net/ipv4/tcp_bic

Enabling binary increase congestion for fast, long-distance networks allows for better use of links that operate at GB speed, which should be enabled for WAN traffic.

1

/etc/sysctl.conf file

/etc/sysctl.conf is an interface that allows you to change a running Linux system. It contains advanced options for the TCP/IP stack and virtual memory system, which can be used to control the Linux network configuration, because the/proc/sys/net directory content is temporary, it is recommended to add the TCPIP parameter modification to the/etc/sysctl.conf file, and then save the file, Use the command "/sbin/sysctl–p" to make it effective immediately. Specific modifications to the scheme are referred to above:

Net.core.rmem_default = 256960

Net.core.rmem_max = 513920

Net.core.wmem_default = 256960

Net.core.wmem_max = 513920

Net.core.netdev_max_backlog = 2000

Net.core.somaxconn = 2048

Net.core.optmem_max = 81920

Net.ipv4.tcp_mem = 131072 262144 524288

Net.ipv4.tcp_rmem = 8760 256960 4088000

Net.ipv4.tcp_wmem = 8760 256960 4088000

Net.ipv4.tcp_keepalive_time = 1800

NET.IPV4.TCP_KEEPALIVE_INTVL = 30

Net.ipv4.tcp_keepalive_probes = 3

Net.ipv4.tcp_sack = 1

Net.ipv4.tcp_fack = 1

Net.ipv4.tcp_timestamps = 1

net.ipv4.tcp_window_scaling = 1

Net.ipv4.tcp_syncookies = 1

Net.ipv4.tcp_tw_reuse = 1

Net.ipv4.tcp_tw_recycle = 1

Net.ipv4.tcp_fin_timeout = 30

Net.ipv4.ip_local_port_range = 1024 65000

Net.ipv4.tcp_max_syn_backlog = 2048

Go to: http://www.cnblogs.com/fczjuever/archive/2013/04/17/3026694.html

Rules for determining the size of TCP and UDP socket-to-receive buffers under LINUX

1. TCP send and receive buffers default values

[Email protected] core]# Cat/proc/sys/net/ipv4/tcp_rmem
4096 87380 4161536

87380:tcp the default value of the receive buffer

[Email protected] core]# Cat/proc/sys/net/ipv4/tcp_wmem
4096 16384 4161536

16384:tcp default value of the Send buffer

2. TCP or UDP transmit/receive buffer maximum value

[Email protected] core]# Cat/proc/sys/net/core/rmem_max
131071

The 131071:TCP or UDP receive buffer can be half the maximum set value.

That means call setsockopt (S, Sol_socket, So_rcvbuf, &rcv_size, &optlen); If the rcv_size is more than 131071, then

GetSockOpt (S, Sol_socket, So_rcvbuf, &rcv_size, &optlen); The value to go to is equal to 131071 * 2 = 262142

[Email protected] core]# Cat/proc/sys/net/core/wmem_max
131071

The maximum set of 131071:TCP or UDP send buffers is worth half.

With the same principle as above

3. UDP transmit/Receive buffer default value

[Email protected] core]# Cat/proc/sys/net/core/rmem_default
111616:UDP the default value of the receive buffer

[Email protected] core]# Cat/proc/sys/net/core/wmem_default
111616

111616:UDP default value of the Send buffer

4. TCP or UDP transmit/receive buffer minimum value

The minimum value for the TCP or UDP receive buffer is bytes, which is determined by the kernel macro;

The minimum value for the TCP or UDP send buffer is 2048 bytes, which is determined by the kernel's macro

Linux TCPIP kernel parameter optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.