TCP系列53—拥塞控制—16、Destination Metrics和Congestion Manager
一、概述
我们之前介绍过rtt、ssthresh等变量,这些变量一般在TCP连接建立的时候有个初始值,然后随着TCP的数据交互逐渐调整到适应对应的网络状态的值。但是如果每次TCP建立连接都依靠默认初始值逐渐调整,那么可能需要一段时间才能调整到合适值,这显然会降低TCP性能,对于这种场景一种优化方案就是_cc/tcp17# ip route add local 127.0.0.2 dev lo congctl reno initcwnd 5 ssthresh lock 4
#设置后查看一下相关信息****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2#下面一行对应 ip route show table all | grep 127.0.0.2 该命令可以查看destination metrics设置local 127.0.0.2 dev lo table local scope host ssthresh lock 50 cwnd lock 9 initcwnd 5 congctl reno#下面一行对应命令 ss -i sport = 9877 查看源端口为9877 的tcp连接信息Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port #下面一行对应 ip tcp_metrics show 127.0.0.2 该命令可以查看tcp metrics设置,此时我们虽然设置了destination metric,但是因为#还没有建立到127.0.0.2的tcp连接,因而还没有tcp metric信息RTNETLINK answers: No such process#启动server server端在与client建立连接后会休眠30ms 然后连续发送15个数据包 每个数据包的大小为50bytes,发送间隔为3ms#数据包发送完后休眠30s,然后关闭与client的连接****@Inspiron:****/04_cc/tcp17# ./server.out &[1] 24091#client建立与server端的tcp连接,client对于每个收到的数据包都会回复一个ACK确认包****@Inspiron:****/04_cc/tcp17# ./client.out > rst_client &[2] 24093****@Inspiron:****/04_cc/tcp17# conn setup sleep 30s#上面一行是server端打印,提示已经与client建立连接,开始休眠30s,此时我们再次查看信息****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2#可以看到路由表中的destination metric的设置值是静态不变的local 127.0.0.2 dev lo table local scope host ssthresh lock 50 cwnd lock 9 initcwnd 5 congctl reno#现在可以查看到server端与client端的连接了 注意路由表中设置了ssthresh lock 50,但是下面的连接信息告诉我们server端ssthresh=9,原因就是路由表中设置了cwnd lock 9,cwnd这个metric生效的时候,TCP连接会设置ssthresh=min(ssthresh,cwnd)=9Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:252 rtt:50.258/25.129 mss:50 cwnd:5 ssthresh:9 segs_in:2 send 39.8Kbps lastsnd:6064456 lastack:6064456 pacing_rate 47.8Kbps rcv_space:43690#可以看到在新建立TCP连接后,就会初始化一个tcp metric,初始值来自路由表中静态的destination metric 127.0.0.2 age 4.760sec ssthresh 50 cwnd 9 source 127.0.0.1****@Inspiron:****/04_cc/tcp17# ****@Inspiron:****/04_cc/tcp17# server send startserver send end sleep 30s#server端发送数据后再次查看相关信息****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh lock 50 cwnd lock 9 initcwnd 5 congctl reno#由于路由表中设置cwnd lock 9,限制了拥塞窗口最大值只能到9,注意路由表中的cwnd限制的是拥塞窗口的最大值,从下面连接信息可以看到cwnd=9Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:252 rtt:50.271/0.392 mss:50 cwnd:9 ssthresh:9 bytes_acked:750 segs_out:15 segs_in:17 send 71.6Kbps lastsnd:6094556 lastack:6094604 pacing_rate 85.9Kbps rcv_space:43690#从下面的age可以看到server端并没有更新tcp metrics127.0.0.2 age 39.528sec ssthresh 50 cwnd 9 source 127.0.0.1****@Inspiron:****/04_cc/tcp17# server sockfd close[2]+ 已完成 ./client.out > rst_client#server端连接关闭,再次查看相关信息****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh lock 50 cwnd lock 9 initcwnd 5 congctl reno#已经查不到源端口为9877的tcp连接Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port #可以从age信息里面看到tcp 连接关闭的时候更新了tcp metric,但是可以看到ssthresh和cwnd的值并没有更新这个就是lock的作用,#被lock的tcp metric是不会被tcp连接更新的 另外可以看到rtt和rttvar这两个metric发生了更新,但是reordering并没有更新,也就是说TCP#连接关闭的时候还要检测当前状态的有效性来决定是否更新相关的metric。127.0.0.2 age 6.116sec ssthresh 50 cwnd 9 rtt 50281us rttvar 50281us source 127.0.0.1#接下来我们更新路由表destination metric的cwnd和ssthresh两个metrics****@Inspiron:****/04_cc/tcp17# ip route change local 127.0.0.2 dev lo initcwnd 5 cwnd lock 8 ssthresh lock 40 congctl reno****@Inspiron:****/04_cc/tcp17# ./client.out > rst_client &[2] 24190****@Inspiron:****/04_cc/tcp17# conn setup sleep 30s#重新进行测试 连接建立****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh lock 40 cwnd lock 8 initcwnd 5 congctl reno#从下面的连接信息中的ssthresh值可以看到,路由表中的设置并没有生效,连接建立的时候是从tcp metrics中读取的连接缓存信息Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:248 rtt:50.225/25.112 mss:50 cwnd:5 ssthresh:9 segs_in:2 send 39.8Kbps lastsnd:6393360 lastack:6393360 pacing_rate 47.8Kbps rcv_space:43690#可以看到此时的tcp metric中cwnd和ssthresh并没有从destination中更新,原因就是上面说的#只有TCP metrics过期后或者初始建立时候才会从destination metric更新 127.0.0.2 age 273.460sec ssthresh 50 cwnd 9 rtt 50281us rttvar 50281us source 127.0.0.1****@Inspiron:****/04_cc/tcp17# server send startserver send end sleep 30s****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh lock 40 cwnd lock 8 initcwnd 5 congctl renoNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:252 rtt:50.306/0.377 mss:50 cwnd:9 ssthresh:9 bytes_acked:750 segs_out:15 segs_in:17 send 71.6Kbps lastsnd:6423460 lastack:6423508 pacing_rate 85.9Kbps rcv_space:43690127.0.0.2 age 303.164sec ssthresh 50 cwnd 9 rtt 50281us rttvar 50281us source 127.0.0.1****@Inspiron:****/04_cc/tcp17# server sockfd close[2]+ 已完成 ./client.out > rst_client****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh lock 40 cwnd lock 8 initcwnd 5 congctl renoNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port #连接关闭后 再次更新了tcp metrics 这一点可以从age看到 也可以从rtt、rttvar中看到 127.0.0.2 age 4.800sec ssthresh 50 cwnd 9 rtt 50312us rttvar 37785us source 127.0.0.1#接下来我们看一下不填加lock关键字的效果****@Inspiron:****/04_cc/tcp17# ip route change local 127.0.0.2 dev lo initcwnd 5 cwnd 8 ssthresh 40 congctl reno****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl renoNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port 127.0.0.2 age 91.740sec ssthresh 50 cwnd 9 rtt 50312us rttvar 37785us source 127.0.0.1#为了让路由表中的destination metric生效,需要使用下面的命令从tcp metrics中删除127.0.0.2对应的缓存信息****@Inspiron:****/04_cc/tcp17# ip tcp_metrics flush 127.0.0.2****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl renoNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port #可以看到TCP metrics中已经没有对应127.0.0.2的缓存了RTNETLINK answers: No such process****@Inspiron:****/04_cc/tcp17# ./client.out > rst_client &[2] 24265****@Inspiron:****/04_cc/tcp17# conn setup sleep 30s#client再次建立连接 进行新的测试****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl reno#从下面的连接信息中可以看到,cwnd虽然设置了 但是并没有限制到server端的拥塞窗口,因为如果cwnd这个metric设置生效的话,那么ssthresh应为8Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:252 rtt:50.243/25.121 mss:50 cwnd:5 ssthresh:40 segs_in:2 send 39.8Kbps lastsnd:6574128 lastack:6574128 pacing_rate 79.6Kbps rcv_space:43690#连接建立后创建新的tcp metric,可以看到其中的初始值来自与路由表中destination metrics设置127.0.0.2 age 2.980sec ssthresh 40 cwnd 8 source 127.0.0.1****@Inspiron:****/04_cc/tcp17# server send startserver send end sleep 30s****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl reno#server端发送数据后,可以看到cwnd已经增长到了20,超越了路由表中cwnd的设置。说明没有添加lock关键字的cwnd metric并没有生效Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:252 rtt:50.273/0.372 mss:50 cwnd:20 ssthresh:40 bytes_acked:750 segs_out:15 segs_in:17 send 159.1Kbps lastsnd:6604192 lastack:6604244 pacing_rate 191.0Kbps rcv_space:43690127.0.0.2 age 34.248sec ssthresh 40 cwnd 8 source 127.0.0.1****@Inspiron:****/04_cc/tcp17# server sockfd close[2]+ 已完成 ./client.out > rst_client****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl renoNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port #因为路由表中的cwnd metric没有lock,因此连接关闭的时候会更新cwnd,实际上更新了也没用,因为新的tcp连接并不会使用127.0.0.2 age 3.064sec ssthresh 40 cwnd 24 rtt 50275us rttvar 50275us source 127.0.0.1#接着进行新的测试,下面命令指示client丢掉第8个数据包 造成server端快速重传,从而更新ssthresh****@Inspiron:****/04_cc/tcp17# ./client.out 8 >rst_client &[2] 24606****@Inspiron:****/04_cc/tcp17# conn setup sleep 30s****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl reno#新建立连接的拥塞窗口cwnd始终从路由表中的initcwnd初始化 而不是从tcp metric或者destination metric中的cwnd metric更新,#再说一次 cwnd这个metric限制的是拥塞窗口的最大值,而且只有在加lock关键字设置后才会生效Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:252 rtt:50.287/25.143 mss:50 cwnd:5 ssthresh:40 segs_in:2 send 39.8Kbps lastsnd:7230928 lastack:7230928 pacing_rate 79.5Kbps rcv_space:43690127.0.0.2 age 601.280sec ssthresh 40 cwnd 24 rtt 50275us rttvar 50275us source 127.0.0.1****@Inspiron:****/04_cc/tcp17# server send startserver send end sleep 30s****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl reno#快速重传及快速恢复后,cwnd=7,ssthresh=6Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp ESTAB 0 0 127.0.0.1:9877 127.0.0.2:webmin reno wscale:0,7 rto:252 rtt:49.999/0.534 mss:50 cwnd:7 ssthresh:6 bytes_acked:750 segs_out:16 segs_in:17 send 56.0Kbps lastsnd:7261040 lastack:7261088 pacing_rate 67.2Kbps retrans:0/1 rcv_space:43690127.0.0.2 age 630.636sec ssthresh 40 cwnd 24 rtt 50275us rttvar 50275us source 127.0.0.1****@Inspiron:****/04_cc/tcp17# server sockfd close[2]+ 已完成 ./client.out 8 > rst_client****@Inspiron:****/04_cc/tcp17# ip route show table all | grep 127.0.0.2; ss -i sport = 9877;ip tcp_metrics show 127.0.0.2local 127.0.0.2 dev lo table local scope host ssthresh 40 cwnd 8 initcwnd 5 congctl renoNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port #连接关闭后 可以看到cwnd和ssthresh都已经更新了 127.0.0.2 age 4.996sec ssthresh 6 cwnd 15 rtt 50244us rttvar 37823us source 127.0.0.1****@Inspiron:****/04_cc/tcp17# 补充说明:
1、实际在TCP metrics中有7个参数,但是有两个是冗余的,主要是为了接口兼容保留下来的,参考kernel修改https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=740b0f1841f6e39085b711d41db9ffb07198682b&dt=1,Iproute2配套修改 https://patchwork.ozlabs.org/patch/386544/,Iproute2即为ss命令的程序包,Iproute2还包含其他的一些命令,用来取代net-tools程序包,net-tools程序包就是netstat/ip等程序所在的软件包。
2、TCP metrics枚举tcp_metric_index、TCP_METRICS_ATTR_UNSPEC,destination metric枚举RTAX_UNSPEC
3、连接建立时候更新metric信息初始化连接状态变量tcp_init_metrics,连接关闭时候更新tcp metrics代码点tcp_update_metrics
4、显然TCPIP详解中对于destination metric中,cwnd的解释也是错误的了。
TCP系列53—拥塞控制—16、Destination Metrics和Congestion Manager的更多相关文章
- TCP系列39—拥塞控制—2、拥塞相关算法及基础知识
一.拥塞控制的相关算法 早期的TCP协议只有基于窗口的流控(flow control)机制而没有拥塞控制机制,因而易导致网络拥塞.1988年Jacobson针对TCP在网络拥塞控制方面的不足,提出了& ...
- TCP系列55—拥塞控制—18、其他拥塞控制算法及相关内容概述
前面我们演示分析了100+个wireshark TCP实例,拥塞控制部分也介绍常见的拥塞处理场景以及4种拥塞撤销机制,但是我们一直使用的都是reno拥塞控制算法.实际上拥塞控制发展到今天已经有了各种各 ...
- TCP系列54—拥塞控制—17、AQM及ECN
一.概述 ECN的相关内容是在RFC3168中定义的,这里我简单描述一下RFC3168涉及的主要内容. 1.AQM和RED 目前TCP中多数的拥塞控制算法都是通过缓慢增加拥塞窗口直到检测到丢包来进行慢 ...
- TCP系列47—拥塞控制—10、FACK下的快速恢复与PRR
一.概述 FACK下的重传我们在之前的重传部分已经进行了介绍,这里简单介绍一下随着FACK提出的拥塞控制算法的改进及随后的进一步改进. 从我们之前介绍的RFC2582和RFC5681中可以看到,快速恢 ...
- TCP系列46—拥塞控制—9、SACK下的快速恢复与Limited transmit
一.概述 1.SACK下的特殊处理过程 SACK下的拥塞控制处理是linux中拥塞控制的实现依据,再次强调一遍RFC6675的重要性,linux中拥塞控制主体框架的实现是与RFC6675一致的,所以如 ...
- TCP系列45—拥塞控制—8、SACK关闭的拥塞撤销与虚假快速重传
一.概述 这篇文章介绍一下TCP从Recovery状态恢复到Open状态的时候cwnd的更新.我们在tcp重传部分的文章中曾经介绍过虚假重传的概念,Linux在探测到虚假重传的时候就会执行拥塞撤销操作 ...
- TCP系列44—拥塞控制—7、SACK关闭的快速恢复
) return; delta = ssthresh - in_flight; prr_delivered += newly_acked_sacked; if (delta < 0 ...
- TCP系列52—拥塞控制—15、前向重传与RACK重传拥塞控制处理对比
一.概述 这里主要简单分析一个丢包重传并恢复的场景,通过不同的设置让这个相同的场景分别触发RACK重传和前向重传,通过对比说明以下问题: Forward Retransmit可以产生只有重传标记的数据 ...
- TCP系列51—拥塞控制—14、TLP、ER与拥塞控制
一.概述 这里的重点是介绍TLP.ER与拥塞控制并不是介绍TLP和ER本身,因此TLP和ER的详细内容请翻前文. 在TLP与拥塞控制的交互中有几个点需要注意 1.TLP触发的重传后,TCP仍然处于Op ...
随机推荐
- C++快速开发样本工程的建立--简介
背景 在开发项目过程中,一些功能库能反复被写被用,可以写成库被重用: 但是行业业务也随着换项目,每次重新写一次,如果把一些功能业务和框架绑定,配置绑定,只需要添加,修改,增加业务功能,就可以搭建C++ ...
- [转]Kafka 设计与原理详解
一.Kafka简介 本文综合了我之前写的kafka相关文章,可作为一个全面了解学习kafka的培训学习资料. 1 2 1 2 转载请注明出处 : 本文链接 1.1 背景历史 当今社会各种应用系统诸如商 ...
- react router animation example
https://github.com/reactjs/react-router/tree/80c71d57c936ed54babdde44309c01f6a4b56b77/examples/anima ...
- 2017-2018-1 20155226 《信息安全系统设计基础》课下实践——实现mypwd
2017-2018-1 20155226 <信息安全系统设计基础>课下实践--实现mypwd 1 学习pwd命令 输入pwd命令 发现他是给出当前文件夹的绝对路径. 于是 man 1 pw ...
- 2017-2018-1 20155331 课下测试(ch10)
2017-2018-1 20155331 课下测试(ch10) 假设下面代码中的foobar.txt中有6个ASCII字母,程序的输出是(A) Image 7.png A . c = f B . c ...
- 20145209刘一阳《JAVA程序设计》第八周课堂测试
第八周课堂测试 1.下面代码中共有(C)个线程? public class ThreadTest { public static void main(String args[]){ MyThread ...
- 如何搭建openvpn
一.什么是openvpn Openvpn是一款基于openssl的开源vpn软件,它可以很好的运行在linux及windows各发行版本中,它的核心技术是虚拟网卡,其实它更像是一个底层的网卡驱动软件, ...
- 【转载】MSXML应用总结 概念篇
原文:http://blog.sina.com.cn/s/blog_48f93b530100e9tr.html 微软提供了大量的XML开发工具和技术,而SMXML(Microsoft XML Core ...
- 13-[Mysql]--pymysql模块
1.介绍 之前我们都是通过MySQL自带的命令行客户端工具mysql来操作数据库,那如何在python程序中操作数据库呢?这就用到了pymysql模块,该模块本质就是一个套接字客户端软件,使用前需要事 ...
- bootstrap学习笔记(5)
Bootstrap输入框组 主要记住一个原则 创建输入框的步骤 把前缀或后缀元素放在一个带有 class .input-group 的 <div> 中. 接着,在相同的 <div&g ...