测量 GPRS 和 3G 带宽的正确方法

发布于 2025-01-04 06:45:37 字数 2345 浏览 1 评论 0原文

我需要测量多个 GPRS 和 3G BlackBerry 设备的实际传输速率。由于这些数据取决于运营商和设备,并且大多数在线速度测试依赖于 JavaScript、Flash 或 HTML5,因此我觉得有必要开发自己的基准测试应用程序。

由于我没有任何服务器来打开套接字,但我可以在公司中使用多个 HTTP 服务器,因此我使用 HTTPConnection 来获取文件 (HTTP GET) 并发布号码字节数 (HTTP POST),然后测量经过的时间。下载速度似乎是正确的,并且与我在互联网上找到的已知速度限制一致,但上传测试产生了完全出乎意料的结果,比下载速度快了几倍,也比理论上传速度限制大。也在模拟器和真实设备上进行了测试。这是上传测试的代码:

    Httpconnectionection connection = null;
    OutputStream os = null;

    try {
        connection = getHttpconnectionection(url);
        if(connection != null){
            connection.setRequestMethod(Httpconnectionection.POST);

            os = connection.openOutputStream();
            for(int i = 0; i < numbytes; i++){
                os.write(0);                        
            }
            os.flush();

            int respCode = connection.getResponseCode();
            if (respCode != Httpconnectionection.HTTP_OK) {
                userMessage = "HTTP Response code: " + respCode + "\nMessage: " + connection.getResponseMessage();
            }
        } else {
            userMessage = "unable to connnect";
        }                   
    } catch (IOException e) {
        userMessage = e.toString();
    } finally {
        if(os != null){
            try {
                os.close();
            } catch (IOException e) {}
        }

        if(connection != null){
            try {
                connection.close();
            } catch (IOException e) {}
        }
    }

如果我要在 JavaSE 或 Android 上执行类似的测试,此测试是否正确?我做错了什么吗?我在这里很困惑。

我的第二个问题是针对 BlackBerry 的:我知道在 BlackBerry 中 MDS 增加了一些压缩。难道模拟器和设备(我的所有设备都在 BIS 或 BES 上)都会压缩发送的数据(全部为零,因此非常适合压缩),这样测试就不会计算发送的实际字节数但压缩的呢?


更新:关于我的第二个问题,我怀疑 MDS 可能正在压缩,所以我更改了这一问题的写入行,以向测试添加熵:

os.write(i);

我还更新了测试工具以支持不同的连接模式,并按照 MrVincenzo 的建议直接使用 TCP 进行测试。结果如下:

-------------------------------------------------------------
|   Connection Mode |   Mean Speed (3G) |   Mean Speed(GPRS)|
-------------------------------------------------------------
|   BIS             |   390 Kbps        |   90 Kbps         |
|   Direct TCP      |   255 Kbps        |   17 Kbps         |
-------------------------------------------------------------

这证明 MDS 压缩了数据,并且我最初发送的一系列零很可能经历了高度压缩。现在 GPRS 下直接 TCP 的 17 Kbps 对我来说听起来更合理。

I need to measure real transfer rates in several GPRS and 3G BlackBerry devices. Since this data depends on the carrier and the device, and most online speed tests rely on JavaScript, Flash or HTML5, I felt the need to develop my own benchmarking app.

As I don't have any server to open a socket, but I can use several HTTP servers in my company, I'm using an HTTPConnection to get a file (HTTP GET) and to post a number of bytes (HTTP POST), then measuring the elapsed time. The download speed seems correct and is consistent with the known speed bounds I found in the internet, but the upload test is yielding totally unexpected results, several times greater than the download speed, and also greater than the theoretical upload speed limits. Tested on simulators and real devices as well. This is the code for the upload test:

    Httpconnectionection connection = null;
    OutputStream os = null;

    try {
        connection = getHttpconnectionection(url);
        if(connection != null){
            connection.setRequestMethod(Httpconnectionection.POST);

            os = connection.openOutputStream();
            for(int i = 0; i < numbytes; i++){
                os.write(0);                        
            }
            os.flush();

            int respCode = connection.getResponseCode();
            if (respCode != Httpconnectionection.HTTP_OK) {
                userMessage = "HTTP Response code: " + respCode + "\nMessage: " + connection.getResponseMessage();
            }
        } else {
            userMessage = "unable to connnect";
        }                   
    } catch (IOException e) {
        userMessage = e.toString();
    } finally {
        if(os != null){
            try {
                os.close();
            } catch (IOException e) {}
        }

        if(connection != null){
            try {
                connection.close();
            } catch (IOException e) {}
        }
    }

Is this test correct if I were to execute a similar one on JavaSE or Android? Am I doing something wrong? I'm puzzled here.

My second question is more BlackBerry-specific: I know that in BlackBerry the MDS adds some compression. Could it be that both simulators and devices (all my devices are on BIS or BES) compress the sent data (which are all zeroes, so very good to be compressed) and in so doing the test does not count the real number of bytes sent but the compressed ones?


UPDATE: About my second question, I suspected the MDS might be compressing so I changed the write line for this one, to add enthropy to the test:

os.write(i);

I also updated the test harness to support different connection modes and test with TCP direct as MrVincenzo suggested. these are the results:

-------------------------------------------------------------
|   Connection Mode |   Mean Speed (3G) |   Mean Speed(GPRS)|
-------------------------------------------------------------
|   BIS             |   390 Kbps        |   90 Kbps         |
|   Direct TCP      |   255 Kbps        |   17 Kbps         |
-------------------------------------------------------------

This proves that MDS compresses the data, and the series of zeroes I was sending at first was very likely undergoing high compression. Now the 17 Kbps for direct TCP under GPRS sounds a lot more reasonable to me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新雨望断虹 2025-01-11 06:45:37
  1. 我从来没有在 JavaSE 和 Android 上工作过,但恕我直言,你的上传测试的概念似乎是正确的,我也会做同样的事情,但有一点不同。我会打开 SocketConnection(到 HTTP 服务器或专用服务器)而不是 HttpConnection。原因更多地基于直觉,而不是真实的事实。
    如果您决定使用专用服务器,则应考虑 Amazon EC2 按需实例,它提供按小时使用的专用服务器且价格非常低。我过去曾使用它们进行压力和负载测试。

  2. 对于第二个问题,如果可能的话,我建议使用直接 TCP 连接重复测试,看看会发生什么。这样你就可以判断MDS是否压缩了发送的数据。

  1. I've never worked neither on JavaSE nor on Android but IMHO the concept of your upload test seems correct and I would have done the same with one difference. I would have opened SocketConnection (to an HTTP server or to a dedicated server) instead of HttpConnection. The reason is based more on gut feeling then on real facts.
    If you decide to go with dedicated server, you should consider the Amazon EC2 On-Demand Instances that provides dedicated server(s) for hourly usage and very low pricing. I had used them in the past for stress and load tests.

  2. As for the second question, I'd suggest to repeat the test with direct TCP connection if possible and see what happens. This way you will be able to determine whether MDS compresses the sent data or not.

2025-01-11 06:45:37

使用直接 TCP 连接运行代码,并将 deviceside=true 添加到由 Connector.open() 传递的 url 中。这可能对你有帮助。

Run your code with direct TCP connection and add deviceside=true to the url i.e. passed by Connector.open(). This may be help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文