tcp 重传超时次数
数据被重发以后若还是收不到应答, 则进行再次发送. 此时等待确认应答时间会以 2 倍, 4 倍的指数函数延长.
此外, 数据也不会被无限, 反复的重发. 达到一定的重发次数之后, 如果仍然没有任何确认应答返回, 就会判断为网络或者对端主机发生了异常, 强制关闭连接.
Linux 的设置
最小重传时间是 200ms
最大重传时间是 120s
重传次数为 15TCP retransmits an unacknowledged packet up to tcp_retries2 sysctl setting times(defaults to15)usingan exponential backoff timeoutforwhich each retransmission timeoutisbetween TCP_RTO_MIN(200ms)andTCP_RTO_MAX(120seconds).Oncethe15thretryexpires(bydefault),the TCP stack will notify the layers above(IE.App)ofa broken connection.
ThevalueofTCP_RTO_MINandTCP_RTO_MAXishardcodedintheLinuxkernelanddefinedbythe following constants:
#defineTCP_RTO_MAX((unsigned)(120*HZ))
#defineTCP_RTO_MIN((unsigned)(HZ/5))
Linux 2.6+ uses HZ of 1000ms, so TCP_RTO_MIN is ~200 ms and TCP_RTO_MAX is ~120 seconds. Given a default value of tcp_retries set to 15, it means that it takes 924.6 seconds before a broken network link is notified to the upper layer (IE. application), since the connection is detected as broken when the last (15th) retry expires.
image.PNGFromtheLinuxkernel doc
tcp_retries2-INTEGER
Thisvalueinfluences the timeoutofan alive TCP connection,
when RTO retransmissions remain unacknowledged.GivenavalueofN,a hypothetical TCP connection following
exponential backoffwithan initial RTOofTCP_RTO_MIN would
retransmit N times before killing the connection at the(N+1)th RTO.
Thedefaultvalueof15yields a hypothetical timeoutof924.6
secondsandisa lower boundforthe effective timeout.
TCP will effectively timeoutat the first RTO which exceeds the
hypothetical timeout.
RFC1122recommends at least100secondsforthe timeout,
which corresponds to avalueofat least8.
参考地址
https://pracucci.com/linux-tcp-rto-min-max-and-tcp-retries2.html
来源: http://www.jianshu.com/p/51d7f7fb3e4b