Linux TCP Tuning(Tcp优化)

转载 2007年09月20日 02:29:00

Linux TCP Tuning
There are a lot of differences between Linux version 2.4 and 2.6, so first we'll cover the tuning issues that are the same in both 2.4 and 2.6. To change TCP settings in, you add the entries below to the file /etc/sysctl.conf, and then run "sysctl -p".

Like all operating systems, the default maximum Linux TCP buffer sizes are way too small. I suggest changing them to the following settings:

  # increase TCP max buffer size
net.core.rmem_max =
net.core.wmem_max =
# increase Linux autotuning TCP buffer limits
# min, default, and max number of bytes to use
net.ipv4.tcp_rmem =
net.ipv4.tcp_wmem =

Note: you should leave tcp_mem alone. The defaults are fine.

Another thing you can try that may help increase TCP throughput is to increase the size of the interface queue. To do this, do the following:
     ifconfig eth0 txqueuelen  

I've seen increases in bandwidth of up to 8x by doing this on some long, fast paths. This is only a good idea for Gigabit Ethernet connected hosts, and may have other side effects such as uneven sharing between multiple streams.

Linux 2.4
Starting with Linux 2.4, Linux has implemented a sender-side autotuning mechanism, so that setting the opitimal buffer size on the sender is not needed. This assumes you have set large buffers on the recieve side, as the sending buffer will not grow beyond the size of the recieve buffer.

However, Linux 2.4 has some other strange behavior that one needs to be aware of. For example: The value for ssthresh for a given path is cached in the routing table. This means that if a connection has has a retransmition and reduces its window, then all connections to that host for the next 10 minutes will use a reduced window size, and not even try to increase its window. The only way to disable this behavior is to do the following before all new connections (you must be root):

sysctl -w net.ipv4.route.flush=1
More information on various tuning parameters for Linux 2.4 are available in the Ipsysctl tutorial .

Linux 2.6
Starting in Linux 2.6.7 (and back-ported to 2.4.27), BIC TCP is part of the kernel, and enabled by default. BIC TCP helps recover quickly from packet loss on high-speed WANs, and appears to work quite well. A BIC implementation bug was discovered, but this was fixed in Linux 2.6.11, so you should upgrade to this version or higher.

Linux 2.6 also includes and both send and receiver-side automatic buffer tuning (up to the maximum sizes specified above). There is also a setting to fix the ssthresh caching weirdness described above.

There are a couple additional sysctl settings for 2.6:
   # don
net.ipv4.tcp_no_metrics_save =
# recommended to increase BT or higher
net.core.netdev_max_backlog =
# GigE, use
# net.core.netdev_max_backlog =

Starting with version 2.6.13, Linux supports pluggable congestion control algorithms . The congestion control algorithm used is set using the sysctl variable net.ipv4.tcp_congestion_control, which is set to Reno by default. (Apparently they decided that BIC was not quite ready for prime time.) The current set of congestion control options are:

reno: Traditional TCP used by almost all other OSes. (default)
bic: BIC-TCP
highspeed: HighSpeed TCP: Sally Floyd's suggested algorithm
htcp: Hamilton TCP
hybla: For satellite links
scalable: Scalable TCP
vegas: TCP Vegas
westwood: optimized for lossy networks
For very long fast paths, I suggest trying HTCP or BIC-TCP if Reno is not is not performing as desired. To set this, do the following:

sysctl -w net.ipv4.tcp_congestion_control=htcp
More information on each of these algorithms and some results can be found here .

Note: Linux 2.6.11 and under has a serious problem with certain Gigabit and 10 Gig ethernet drivers and NICs that support "tcp segmentation offload", such as the Intel e1000 and ixgb drivers, the Broadcom tg3, and the s2io 10 GigE drivers. This problem was fixed in version 2.6.12. A workaround for this problem is to use ethtool to disable segmentation offload:

ethtool -K eth0 tso off
This will reduce your overall performance, but will make TCP over LFNs far more stable.
More information on tuning parameters and defaults for Linux 2.6 are available in the file ip-sysctl.txt, which is part of the 2.6 source distribution.

And finally a warning for both 2.4 and 2.6: for very large BDP paths where the TCP window is > 20 MB, you are likely to hit the Linux SACK implementation problem. If Linux has too many packets in flight when it gets a SACK event, it takes too long to located the SACKed packet, and you get a TCP timeout and CWND goes back to 1 packet. Restricting the TCP buffer size to about 12 MB seems to avoid this problem, but clearly limits your total throughput. Another solution is to disable SACK.

Linux 2.2
If you are still running Linux 2.2, upgrade! If this is not possible, add the following to /etc/rc.d/rc.local

echo 8388608 > /proc/sys/net/core/wmem_max
echo 8388608 > /proc/sys/net/core/rmem_max
echo 65536 > /proc/sys/net/core/rmem_default
echo 65536 > /proc/sys/net/core/wmem_default


高流量大并发Linux TCP性能调优

 其实主要是手里面的跑openvpn服务器。因为并没有明文禁p2p(哎……想想那么多流量好像不跑点p2p也跑不完),所以造成有的时候如果有比较多人跑BT的话,会造成VPN速度急剧下降。   本...
  • Aresiii
  • Aresiii
  • 2015年09月11日 16:51
  • 5959

linux下修改内核参数进行Tcp性能调优 -- 高并发

前言: Tcp/ip协议对网络编程的重要性,进行过网络开发的人员都知道,我们所编写的网络程序除了硬件,结构等限制,通过修改Tcp/ip内核参数也能得到很大的性能提升, 下面就列举一些Tcp...

高流量大并发Linux TCP 性能调优



#sudo vi /etc/sysctl.conf  $ /proc/sys/net/core/wmem_max 最大socket写buffer,可参考的优化值:873200 $ /proc/s...
  • hytfly
  • hytfly
  • 2016年12月01日 21:23
  • 2889


延迟与带宽网站越快,用户黏性越高; 网站越快,用户忠诚度越高; 网站越快,用户转化率越高。 决定网络通信的两个方面:延迟与带宽。 * 延迟: 分组从信息源发送到目的地所需的时间。 * 带宽:...




本文旨在帮助大家理解TCP CUBIC拥塞控制算法背后的点点滴滴以及其方程式为什么就是那样子的。一直以来,很多人都觉得CUBIC算法非常复杂,涉及到复杂的天书般的”3次曲线“...然而,CUBIC并不...
  • dog250
  • dog250
  • 2016年11月02日 22:23
  • 7838

提高 Linux 上 socket 性能

使用 Sockets API,我们可以开发客户机和服务器应用程序,它们可以在本地网络上进行通信,也可以通过 Internet 在全球范围内进行通信。与其他 API 一样,您可以通过一些方法使用 S...


1、查看用户单一进程最大文件打开数[root@localhost ~]# ulimit -n 10242、修改/etc/security/limits.conf文件,添加下面两行,[root@loca...


您举报文章:Linux TCP Tuning(Tcp优化)