我想了解一些关于使用java的带宽和延迟的信息。所有这些都是发送到php服务器的字节数,php服务器回复这些字节的字符串。奇怪的是,对于从4字节到4096字节的分组,响应时间几乎是恒定的,但在较大分组大小(大于4KB)时,响应时间线性增加。 PS:我试图做流量整形,以减少测量的带宽,但同样的问题发生。使用PHP回显服务器测量带宽
这里是Java代码
public void measure() throws IOException {
timeArray = new double[sizeArray.length];
for (int i = 0; i < sizeArray.length; i++) {
URL url = new URL("http://10.10.10.101/test.php?bytes=" +sizeArray[i]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
DataInputStream in = new DataInputStream (connection.getInputStream());
long start = System.nanoTime();
byte [] temp = new byte[sizeArray[i]];
in.readFully(temp);
long end = System.nanoTime();
System.out.println("Size = " + sizeArray[i] + " , time = "+(end - start) +" ");
in.close();
//linear.addPoint(k[i] * Math.pow(10, -6) , (end - start) * Math.pow(10, -9));
// simple.addData(k[i] * Math.pow(10, -6) , (end - start) * Math.pow(10, -9));
timeArray[i] = (end - start);
} finally {
connection.disconnect();
}
}
}
这里是PHP的回声服务器
<?php
$bytes = $_GET["bytes"];
$temp = intval ($bytes);
$result = str_pad("",$temp,"*");
echo($result);
?>
任何机构可以解释这种奇怪的行为的代码?
这可能是由于您的浏览器。 Chrome在为实际请求提供服务之前,对于预先缓存4096个字节而臭名昭着。当您尝试传输内容时,您经常遇到此问题,如下所示:http://www.sitepoint.com/php-streaming-output-buffering-explained/ – EdgeCaseBerg
我试图取消此输出缓冲但也是相同的行为发生。 –