Closed shentu521 closed 5 years ago
最近空下来了,看了下袁总的文章, https://mp.weixin.qq.com/s/Ej63-FTe5-2pkxyXoXBUTw
写的相当棒。
晚上看好看到了计算rtt的部分.
每次发送端发送ack后,服务端会发送对应的SIM_SEG_ACK应答.
函数sim_sender_ack代码片段: ` /计算RTT/ now_ts = GET_SYS_MS();
key.u32 = ack->acked_packet_id; iter = skiplist_search(sender->cache, key); if (iter != NULL){ seg = (sim_segment_t*)iter->val.ptr; //发送时间为: [ seg->timestamp(帧产生的时间) + seg->send_ts ](帧的发送时间) + sender->first_ts ,转为绝对时间 //假设接收端是收到这个包了立刻就发送回来的: //那么RTT = now_ts - seg->timestamp - seg->send_ts -> sender->first_ts ; if (now_ts > seg->timestamp + seg->send_ts + sender->first_ts)//把相对时间转为绝对时间 sim_session_calculate_rtt(s, (uint16_t)(now_ts - seg->timestamp - seg->send_ts - sender->first_ts)); skiplist_remove(sender->cache, key); }`
这里我们sim_session_calculate计算rtt,
`void sim_session_calculate_rtt(sim_session_t* s, uint32_t keep_rtt) { if (keep_rtt < 5) keep_rtt = 5;
s->rtt_var = (s->rtt_var * 3 + SU_ABS(s->rtt, keep_rtt)) / 4; if (s->rtt_var < 10) s->rtt_var = 10; s->rtt = (7 * s->rtt + keep_rtt) / 8; if (s->rtt < 10) s->rtt = 10; /*通知RTT更新*/ if (s->sender != NULL) sim_sender_update_rtt(s, s->sender); if (s->receiver != NULL) sim_receiver_update_rtt(s, s->receiver);
}`
这里计算rtt的过程中,
s->rtt_var = (s->rtt_var * 3 + SU_ABS(s->rtt, keep_rtt)) / 4; if (s->rtt_var < 10) s->rtt_var = 10;
s->rtt = (7 * s->rtt + keep_rtt) / 8; if (s->rtt < 10) s->rtt = 10;
这个计算公式,对应的理论支撑文档在哪里,袁总方便提示下么?
问的问题比较菜,多多体谅,苦笑脸.
去看看经典TCP对RTT的计算,RFC文档里面有描述
最近空下来了,看了下袁总的文章, https://mp.weixin.qq.com/s/Ej63-FTe5-2pkxyXoXBUTw
写的相当棒。
晚上看好看到了计算rtt的部分.
每次发送端发送ack后,服务端会发送对应的SIM_SEG_ACK应答.
函数sim_sender_ack代码片段: ` /计算RTT/ now_ts = GET_SYS_MS();
这里我们sim_session_calculate计算rtt,
`void sim_session_calculate_rtt(sim_session_t* s, uint32_t keep_rtt) { if (keep_rtt < 5) keep_rtt = 5;
}`
这里计算rtt的过程中,
s->rtt_var = (s->rtt_var * 3 + SU_ABS(s->rtt, keep_rtt)) / 4; if (s->rtt_var < 10) s->rtt_var = 10;
这个计算公式,对应的理论支撑文档在哪里,袁总方便提示下么?
问的问题比较菜,多多体谅,苦笑脸.