【问题标题】:How to perform a latency test in iPhone如何在 iPhone 中执行延迟测试
【发布时间】:2011-02-02 15:47:41
【问题描述】:

我想在我的 iPhone 应用程序中针对不同的 url 执行延迟测试,一种方法是对 url 发出异步请求,并根据控件何时到达 connectionDidFinish 委托来测量持续时间,是这样吗iPhone 中测量延迟时间的正确方法或替代方法?

【问题讨论】:

    标签: objective-c cocoa-touch ios4 network-programming network-protocols


    【解决方案1】:

    我不确定您如何定义延迟。查看wiki article 以获得一些说明。

    我会配置响应时间以获取网络延迟的图片,这在移动连接中非常有趣。我在我开发的一个应用程序中使用了这种方法:

    - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
    {  
        ...
        self.reqStart = [NSDate date];
        self.url = [[request URL] absoluteString];
        NSLog(@"--> Requesting : %@", url);
        ...
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse
    {
        NSLog(@"<-- Response time %fs : %@", [[NSDate date] timeIntervalSinceDate:reqStart], url);
        ...
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        NSLog(@"<== Request time %fs : %@", [[NSDate date] timeIntervalSinceDate:reqStart], url);
        ...
    }
    

    Throttling bandwidth 用于模拟器测试可能会很有帮助。

    【讨论】:

    • 这仅在您不使用 NSURLCache、URLProxy 和 URL 加载方案中的任何其他类时才有效
    【解决方案2】:

    将 Mac 的 Airport 共享到 iPhone(将其桥接到以太网)。然后在 Mac 上使用 tcpdump 捕获网络流量,使用 Wireshark 查看 pcap,这将为您提供网络延迟的最佳视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      相关资源
      最近更新 更多