CBS是基于信用的流量整形算法,和简单直接设定上限的策略不同。
设线路总速率是Q Gb/s。
● idle slope:空闲增长率,也就是信用为0等待发送时,信用的增长速率。决定了此通道的长期平均发送速率。直接指定要多少指定多少,单位 bps。
● send slope:发送数据时的信用降低速率,send_slope=idle_slope-Q。
下面证明send_slope=idle_slope-Q。
若send_slope=idle_slope-Q,则idle_slope-send_slope=Q
假设数据链路层发送一帧的时间为t秒。初始信用为credits=0,假设等待t秒后前一帧发完了,立即检查当前信用为
credits=idle_slope * tGb=1t随后开始发送一帧,注意此时发送其实是全速发送的,也就是QGb/s,耗时ts,总数据量是Q * tGb。发送完信用为:
credits=credits+t*send_slope=idle_slope * t+t*send_slope=t * (idle_slope+send_slope)=-8t一帧发完,信用为负,停止发送。以idle_slope的速率等待信用恢复为0,未来等待时长为
-credits / idle_slope = -t * (idle_slope+send_slope) / idle_slope=8t。此时间后信用变为0,不够还要继续等大约一帧时间t。至此一个周期结束,共耗时
t - t * (idle_slope+send_slope) / idle_slope + t = t * (2 - (idle_slope+send_slope) / idle_slope)一个周期内发送了Q * tGb的数据,综合速度为:
Q * tGb / (t * (2 - (idle_slope+send_slope) / idle_slope)) = Q / (2 - (idle_slope * 2-Q) / idle_slope)=idle_slope最后一步看着不好约分,其实硬着头皮通分即可得出结果。
也就是说这段时间内的平均速度是idle_slope,符合预期,证明完毕。