Calculation of RTO in tcp and related open source implementation (Linux kernel, unbound) --- rtt, rttvar, cwnd, ssthresh
https://titanwolf.org/Network/Articles/Article?AID=6d260d47-8ba6-4fa6-ba2f-4dc4c2dd6800#gsc.tab=0
Calculation of RTO in tcp and related open source implementation (Linux kernel, unbound)
1. Concept
RTT: Round trip delay.
RTO: After tcp sends a data packet, it will start a retransmission timer, RTO is the retransmission time of this timer.
Since RTO refers to the estimated timeout time of sending the current data packet this time, then RTO needs a good statistical method to better predict the timeout time of this time.
SRTT: smoothed tound-trip time
RTTVAR: round-trip time variation
Second, we can think of the calculation method (take the average)
For example, the first RTT is 500 milliseconds and the second is 800 milliseconds, then the RTO should be 650 milliseconds when it is sent for the third time.
3. RFC793 calculation method
Similar to taking the average.
3.1 Method
SRTT = ( ALPHA * SRTT ) + ( ( 1-ALPHA ) * RTT )
RTO = min [ UBOUND, max [ LBOUND, ( BETA * SRTT ) ] ]
3.2 Parameter meaning
UBOUND is the maximum value of RTO;
LBOUND is the minimum value of RTO;
The value of ALPHA is 0.8 ~ 0.9;
The value of BETA is 1.3 ~ 2.0.
RFC793: http://tools.ietf.org/html/rfc793
4. Calculation method of paper "Congestion Avoidance and Control"
Compared with RFC793, mean deviation is increased.
4.1 Method
Err ≡ m−a
a ← a + gErr
v ← v + g (| Err | −v)
4.2 Parameter meaning
m is RTT;
a is SRTT;
v is the mean difference;
g is a factor.
4.3 Method changes
Since there may be floating point numbers in the presence of g, we only need to make a change so that g = 1/2 ^ n, then the above equation becomes the following
2 ^ na ← 2 ^ na + Err
2 ^ nv ← 2 ^ nv + g (| Err | −v)
4.4 Pseudocode
/∗ update Average estimator ∗/ m − = (sa >> 3); sa + = m; /∗ update Deviation estimator ∗/ if (m <0) m = −m; m − = (sv >> 2); sv + = m; rto = (sa >> 3) + sv;
paper "Congestion Avoidance and Control": http://ee.lbl.gov/papers/congavoid.pdf
Five, RFC6298 calculation method
5.1 Calculation method
At the first RTT:
SRTT <- R
RTTVAR <- R/2
RTO <- SRTT + max (G, K*RTTVAR)
During subsequent RTT:
RTTVAR <- (1 - beta) * RTTVAR + beta * |SRTT - R'|
SRTT <- (1 - alpha) * SRTT + alpha * R'
RTO <- SRTT + max (G, K*RTTVAR)
5.2 Parameter meaning
R and R 'are RTT;
alpha = 1/8;
beta = 1/4;
K = 4.
5.3 Changed calculation method (this method is the same as the calculation method above)
delta = RTT - SRTT
SRTT = SRTT + g * delta
rttvar = rttvar + h(|delta| - rttvar)
RTO = srtt + 4*rttvar
among them:
g = 1/8
h = 1/4
RFC6298: http://tools.ietf.org/html/rfc6298
6. Some open source implementations of computing RTO
In the Linux kernel: net/ipv4/tcp_input.c tcp_rtt_estimator ()
Unbound: util/rtt.c
Reference materials:
RFC793: http://tools.ietf.org/html/rfc793
paper "Congestion Avoidance and Control": http://ee.lbl.gov/papers/congavoid.pdf
RFC6298: http://tools.ietf.org/html/rfc6298
Calculation of RTO in tcp and implementation under linux: http://www.cnblogs.com/hfww/archive/2012/08/01/2618109.html
TCP reliable transmission and flow control series 3: Retransmission time RTO calculation: http://zenhumany.blog.163.com/blog/static/1718066332010827104042708/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通