This document uses the default configuration of ubuntu 12.04 lts desktop (x64) as an example (the memory of the machine is 4 GB). Read this document first.TCP connection status and closing method and their impact on server and client,TCP Parameter Optimization in WindowsTo learn about TCP optimization.
/Proc/sys/NET directory
All TCP/IP parameters are in the/proc/sys/NET directory (note that modifications to the content in the/proc/sys/NET directory are temporary, any modifications will be lost after the system is restarted), such as the following important parameters:
Parameter (Path+File) |
Description |
Default Value |
Optimization Value |
/Proc/sys/NET/CORE/rmem_default |
The default size of the TCP Data Receiving Window (in bytes ). |
229376 |
256960 |
/Proc/sys/NET/CORE/rmem_max |
Maximum TCP Data Receiving Window (in bytes ). |
131071 |
513920 |
/Proc/sys/NET/CORE/wmem_default |
The default size of the TCP data transmission window (in bytes ). |
229376 |
256960 |
/Proc/sys/NET/CORE/wmem_max |
Maximum TCP data transmission window (in bytes ). |
131071 |
513920 |
/Proc/sys/NET/CORE/netdev_max_backlog |
The maximum number of packets that can be sent to the queue when each network interface receives packets faster than the kernel processes these packets. |
1000 |
2000 |
/Proc/sys/NET/CORE/somaxconn |
Defines the maximum length of the listening queue for each port in the system. This is a global parameter. |
128 |
2048 |
/Proc/sys/NET/CORE/optmem_max |
The maximum buffer size allowed by each socket. |
20480 |
81920 |
/Proc/sys/NET/IPv4/tcp_mem |
Determine how the TCP stack reflects memory usage. The unit of each value is a memory page (usually 4 kb ). The first value is the lower limit of memory usage, the second value is the upper limit of the application pressure on the buffer zone starting from the memory pressure mode, and the third value is the upper limit of memory usage. At this level, messages can be discarded to reduce memory usage. For larger BDP values, you can increase these values (note that the unit is the Memory Page rather than the byte ). |
94011 125351 188022 |
131072 262144 524288 |
/proc/sys/NET/IPv4/tcp_rmem |
defines the memory used by the socket for automatic optimization. The first value is the minimum number of bytes allocated to the socket receiving buffer; the second value is the default value (this value will be overwritten by rmem_default ), the buffer can be increased to this value when the system load is not heavy. The third value is the maximum number of bytes of the received buffer space (this value will be overwritten by rmem_max ). |
4096 87380 4011232 |
8760 256960 4088000 |
/Proc/sys/NET/IPv4/tcp_wmem |
Defines the memory used by the socket for automatic optimization. The first value is the minimum number of bytes allocated for the socket sending buffer; the second value is the default value (this value will be overwritten by wmem_default ), the buffer can be increased to this value when the system load is not heavy. The third value is the maximum number of bytes in the sending buffer space (this value will be overwritten by wmem_max ). |
4096 16384 4011232 |
8760 256960 4088000 |
/Proc/sys/NET/IPv4/tcp_keepalive_time |
The interval (in seconds) between the TCP send keepalive detection message and is used to confirm whether the TCP connection is valid. |
7200 |
1800 |
/Proc/sys/NET/IPv4/tcp_keepalive_intvl |
Interval (in seconds) for resending a message when no response is received ). |
75 |
30 |
/Proc/sys/NET/IPv4/tcp_keepalive_probes |
Maximum number of keepalive probe messages that can be sent before the TCP connection is determined to be invalid. |
9 |
3 |
/Proc/sys/NET/IPv4/tcp_sack |
Enable selective response (1 indicates enabled) to improve performance by selectively responding to messages received in disordered order, so that the sender can send only the lost packet segment (for Wan communication) this option should be enabled, but will increase the CPU usage. |
1 |
1 |
/Proc/sys/NET/IPv4/tcp_fack |
Enable the forwarding response function. You can select a response (sack) to reduce congestion. This option should also be enabled. |
1 |
1 |
/Proc/sys/NET/IPv4/tcp_timestamps |
The TCP timestamp (which will add 12 bytes to the TCP Header) enables RTT calculation in a more precise way (refer to RFC 1323, this option should be enabled for better performance. |
1 |
1 |
/Proc/sys/NET/IPv4/tcp_window_scaling |
Enable the Window Scaling defined in RFC 1323. To support a TCP window larger than 64 KB, you must enable this value (1 indicates enabled). The maximum TCP window size is 1 GB, it takes effect only when both TCP connections are enabled. |
1 |
1 |
/Proc/sys/NET/IPv4/tcp_syncookies |
Indicates whether to enable the TCP synchronization tag (syncookie). The config_syn_cookies must be enabled in the kernel for compilation. The synchronization tag can prevent a socket from overload when too many connections are attempted. |
1 |
1 |
/Proc/sys/NET/IPv4/tcp_tw_reuse |
Indicates whether to allow the time-Wait socket (the port of Time-Wait) to be used for the new TCP connection. |
0 |
1 |
/Proc/sys/NET/IPv4/tcp_tw_recycle |
Time-Wait socket can be recycled more quickly. |
0 |
1 |
/Proc/sys/NET/IPv4/tcp_fin_timeout |
For local-end closed socket connections, TCP stays in the fin-wait-2 State (in seconds ). The other party may disconnect or never end the connection or unexpected process will die. |
60 |
30 |
/Proc/sys/NET/IPv4/ip_local_port_range |
Indicates the local port number allowed by the TCP/UDP protocol |
32768 61000 |
1024 65000 |
/Proc/sys/NET/IPv4/tcp_max_syn_backlog |
For connection requests that have not been confirmed by the other party, the maximum number of connections in the queue can be saved. If the server is overloaded frequently, add this number. |
2048 |
2048 |
/Proc/sys/NET/IPv4/tcp_low_latency |
This option should be disabled to allow TCP/IP stack to adapt to low latency under high throughput. |
0 |
|
/Proc/sys/NET/IPv4/tcp_westwood |
Enable the congestion control on the senderAlgorithmIt can maintain the throughput evaluation and try to optimize the overall utilization of bandwidth. This option should be enabled for Wan communication. |
0 |
|
/Proc/sys/NET/IPv4/tcp_bic |
Enable binary increase congestion for a fast long-distance network so that you can better use the link for operations at the GB speed. This option should be enabled for Wan communication. |
1 |
|
/Etc/sysctl. conf file
/Etc/sysctl. conf is an interface that allows you to change the running Linux system. It includes some advanced options for TCP/IP stack and virtual memory system, which can be used to control Linux network configuration. Due to the temporary content of the/proc/sys/NET directory, we recommend that you add the TCPIP parameter to/etc/sysctl. CONF file, save the file, and use the command "/sbin/sysctl-P" to make it take effect immediately. For specific modification plans, refer to the 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