数据被重发以后若还是收不到应答, 则进行再次发送. 此时等待确认应答时间会以 2 倍, 4 倍的指数函数延长.
此外, 数据也不会被无限, 反复的重发. 达到一定的重发次数之后, 如果仍然没有任何确认应答返回, 就会判断为网络或者对端主机发生了异常, 强制关闭连接.
Linux 的设置
最小重传时间是 200ms
最大重传时间是 120s
重传次数为 15
- TCP retransmits an unacknowledged packet up to tcp_retries2 sysctl setting times (defaults to 15) using an exponential backoff timeout for which each retransmission timeout is between TCP_RTO_MIN (200 ms) and TCP_RTO_MAX (120 seconds). Once the 15th retry expires (by default), the TCP stack will notify the layers above (IE. App) of a broken connection.
- The value of TCP_RTO_MIN and TCP_RTO_MAX is hardcoded in the Linux kernel and defined by the following constants:
- #define TCP_RTO_MAX ((unsigned)(120*HZ))
- #define TCP_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.PNG
- From the Linux kernel doc
- tcp_retries2 - INTEGER
- This value influences the timeout of an alive TCP connection,
when RTO retransmissions remain unacknowledged.
- Given a value of N, a hypothetical TCP connection following
- exponential backoff with an initial RTO of TCP_RTO_MIN would
- retransmit N times before killing the connection at the (N+1)th RTO.
- The default value of 15 yields a hypothetical timeout of 924.6
- seconds and is a lower bound for the effective timeout.
- TCP will effectively time out at the first RTO which exceeds the
- hypothetical timeout.
- RFC 1122 recommends at least 100 seconds for the timeout,
- which corresponds to a value of at least 8.
参考地址
https://pracucci.com/linux-tcp-rto-min-max-and-tcp-retries2.html
来源: http://www.jianshu.com/p/51d7f7fb3e4b