1. 带宽
通信公司一般说的带宽的单位是bps
也就是bit/s
,拿20M的宽带来说吧,20M是指传输速度能达到20Mbit/s, 500M带宽代表500Mbit/s(也可以写成500Mbps)。B
代表字节,b
代表位。而我们平时下载的速度是按照字节(Byte)每秒计算的,20Mbit/s=(20/8)MB/s=2.5MB/s,要除以8是因为1Byte=8bits。
所以:
宽带的带宽为20Mb,下载速度最高为2.50MB/s(20/8);
宽带的带宽为50Mb,下载速度最高为6.25MB/s(50/8);
宽带的带宽为100Mb,下载速度最高为12.5MB/s(100/8)。
以上为理论值,实际应用中,可能会由于你浏览的网站本身服务器的资源问题,家里的路由器的传输速率等因素产生一定的影响,大家平时可使用电信专门的测速页面进行网速测试 ,只要数值不差太多都属于正常范围。
2. 带宽估计
通过实际的网速测试来评估当前的无线设备所处环境的带宽。例如,可以下载一个大的文件,然后观察实际的下载速度。
下载测试法主要是将一个大型的文件放置在服务器上,然后通过下载的方法来对带宽的下载速度和稳定性进行测试,这种方法比较适用,特别是对于搭建下载网站或者在线视频这种需要大带宽支持的用户来说。
下载测试法的步骤如下:
-
在服务器上准备一个大文件,这个文件的大小最好足够大,以便能够充分测试带宽的性能。
-
从客户端设备开始下载这个文件。在这个过程中,你需要注意观察下载速度的变化,看看是否稳定,有没有出现突然变慢或者断开的情况。
-
下载完成后,你可以查看下载的总时间和总字节数,然后通过公式 “下载速度 = 总字节数 / 总时间” 来计算出下载速度。
-
如果条件允许,你还可以多次进行下载测试,每次测试都换一个新的文件,这样可以得到更准确的结果。
下载速度是衡量带宽的一个重要指标。带宽通常指的是网络在单位时间内可以传输的数据量,而下载速度则是在特定条件下,从网络上获取数据的速度。
但是,需要注意的是,下载速度并不等同于带宽。带宽通常以比特每秒(bit/s)为单位,而下载速度通常以字节每秒(Byte/s)为单位。在计算机科学中,1字节等于8比特。因此,如果你有一个1Mbps的带宽,那么理论上你的下载速度应该是125KB/s(1Mbps ÷ 8)。
此外,下载速度也会受到许多其他因素的影响,例如服务器的响应速度、网络的拥堵程度、设备的处理能力等。因此,虽然下载速度不能完全反映带宽,但它仍然是一个非常有用的指标,可以帮助你了解你的网络性能。
3.代码片段
我项目中用到的带宽估计 代码片段, use the Exponential Moving Average (EMA) algorithm in code to estimate available bandwidth
if (endTile == 1) {
// if all tiles of current time slot is delivered, end the estimated throughput duration
calBandEndTime = System.nanoTime();
// estimate the throughput, if it is lower than 0, invalid (ns,us,ms,s)
float estThroughput = (float) (calBandTileLen - Config.PKT_SIZE) * 1000 / (calBandEndTime - calBandBeginTime); // unit: MB/s
float delay = (float) (System.nanoTime() - calBandBeginTime) / 1000000; // unit: ms
ACKmsg = 1 + "," + videoID + "," + ts + "," + endTile + "," + delay + "," + estThroughput;
} else
ACKmsg = 1 + "," + videoID + "," + ts + "," + endTile;
public static float calBandwidth (String indexPos, ArrayList<Integer> tiles, int quality) {
quality = Utils.getCRF (quality); //convert from quality level to CRF
int totalSize = 0;
for (int tile_id : tiles) {
int videoID = Utils.getVideoID (indexPos, tile_id, quality);
if (Utils.id2size.containsKey (videoID))
totalSize += Utils.id2size.get (videoID); // unit: Byte
}
// considering the reservation for decoding
return (float) totalSize / ((Utils.FRAME_PERIOD) * 1000); // unit: MB/s
// totalSize/1000*1000 :Byte->M Byte
// Utils.FRAME_PERIOD / 1000 :ms->s
// (totalSize/1000*1000)/(Utils.FRAME_PERIOD / 1000)=totalSize / ((Utils.FRAME_PERIOD) * 1000) unit: MB/s
}
float estThroughput = Float.parseFloat (tokens[5]);
BigDecimal bd_estThroughput = new BigDecimal(estThroughput);
bd_estThroughput = bd_estThroughput.setScale(2, RoundingMode.HALF_UP); //保留2位小数
estThroughput = bd_estThroughput.floatValue();
// throughput estimation
//To use the Exponential Moving Average (EMA) algorithm in code to estimate available bandwidth
if (estThroughput > 0) {
statistics.estThroughput = statistics.estThroughput * (1 - statistics.expFactor) + estThroughput * statistics.expFactor;
// addEstThroughput(statistics.estThroughput);
}
throughputReport.put (slot, estThroughput);
// System.out.println(Thread.currentThread().getName()+" receive estimated throughput "+estThroughput + " MB/s"); //下载速度
}
4.单位换算
- 1MB=1024KB, 1024MB=1GB,1TB=1024GB,之间采用的是1024进位。这个是容量
如果指计算机数据大小的话: 1G=1024M ;1M=1024K。 - 网络速度一般都是以字节为最小单位,例如KB/s,MB/s。
- 容量是1024M=1G,速度是1G=1000M