如何测试 iPhone 上的低带宽条件
我有一个可以加载大量二进制数据的应用程序。我遇到过这样的情况:在加载某些二进制数据期间,不稳定的 3G 连接可能会间歇性地中断,从而导致问题。
有没有办法使用模拟器或其他方式来测试低带宽/不稳定的连接场景?
我似乎记得 Adobe Flash 在其测试套件中有带宽模拟器。
I have an application that does a lot of binary data loading. I've encountered scenarios where an unstable 3G connection may intermittently cut out during the loading of some of this binary data, causing issues.
Is there any way, using the simulator or otherwise, to test for low-bandwidth/unstable connection scenarios?
I seem to recall Adobe Flash having bandwidth simulators in their test suite.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以通过使用互联网共享在 Mac 上创建无线网络、使用防火墙规则降级该接口并将 iPhone 连接到该网络来实现此目的。这实际上可以用于调试连接到无线网络的任何设备。
使用这种技术,您可以模拟极其微弱、有损或潜在的网络。
我使用这种技术而不是 Apple 的官方网络链接调节器有几个原因:
这使用了 ipfw 的 dummeynet 功能。 ipfw 在现代版本的 OS X 中从技术上来说已被弃用,但它仍然可以正常工作。不幸的是,pf(替代品)尚不支持任意数据包延迟。如果有变化,我会更新这个答案。
创建一个糟糕的 Wi-Fi 网络
告诉 Mac OS 的内置防火墙 (ipfw),以确保应用了延迟的数据包(通过 ipfw 术语中的“dummynet”)仍然通过正常规则进行路由。这允许互联网共享继续工作:
配置 iPhone 流量将通过的低质量管道(14Kb/s 吞吐量,1% 数据包丢失):
下一步根据您是在 Mountain Lion 还是在
对于 Mountain Lion (10.8) 或更低版本:
将数据包路由到管道中,但仅适用于通过 AirPort 接口的流量:
重要:如果如果您使用的是没有物理以太网端口的 Air 或新款 MacBook Pro,您的 AirPort 接口可能会被称为
en0
。如果是这种情况,请将上面的en1
替换为en0
。对于 Mavericks (10.9):
检查
ifconfig
的输出并查找由 Internet 共享创建的桥接接口:您需要具有 IP 地址的桥接接口;在大多数情况下,它将是
bridge100
。将数据包路由到管道中,但仅限于通过桥接接口的流量:
如果
bridge100
在您的系统上有不同的名称,请更改它。模拟不断变化的网络
您可以更改上述步骤 5 中的值
14KB/s
和0.01
来模拟不同类型的网络。您还可以指定config delay 1000
来引入 1000 毫秒的延迟。有关更多选项,请参阅联机帮助页。添加规则后,您可以继续重新配置管道。例如,要模拟接近蜂窝覆盖范围的边缘,请在应用程序运行和连接时发出此命令(95% 数据包丢失):
重新配置后无需再次运行 sudo ipfw add 10 ... 管道。您可以编写这些更改的脚本来模拟极其动态的网络环境。
清理
您可以发出 sudo ipfw delete 10 以使一切恢复正常,或者只是重新启动。
You can accomplish this by creating a wireless network on your Mac using Internet Sharing, degrading that interface using firewall rules, and connecting your iPhone to that network. This will actually work to debug any device that connects to a wireless network.
Using this technique, you can simulate extremely meager, lossy, or latent networks.
I use this technique instead of Apple's official Network Link Conditioner for a couple reasons:
This uses ipfw's
dummeynet
feature. ipfw is technically deprecated in modern versions of OS X, but it still works fine. Unfortunately, pf (the replacement) doesn't yet support arbitrary packet delays. I'll update this answer if something changes.Creating an awful Wi-Fi network
Tell Mac OS's built-in firewall (ipfw) to ensure packets that have latency applied (pass through the "dummynet" in ipfw parlance) are still routed through the normal rules. This allows Internet Sharing to continue working:
Configure the low-quality pipe through which your iPhone's traffic will pass (14Kb/s throughput with 1% packet loss):
The next step varies depending on whether you're on Mountain Lion or below, or Mavericks.
For Mountain Lion (10.8) or below:
Route packets into the pipe, but only for traffic over your AirPort interface:
Important: If you're using an Air or new MacBook Pro without a physical ethernet port, your AirPort interface will likely be called
en0
. Replaceen1
withen0
above if that's the case.For Mavericks (10.9):
Check the output of
ifconfig
and look for the bridge interface created by Internet Sharing:You want the bridge interface that has an IP address; in most cases, it will be
bridge100
.Route packets into the pipe, but only for traffic over the bridge interface:
Change
bridge100
if it has a different name on your system.Simulating a changing network
You can change the values
14KB/s
and0.01
in step 5 above to simulate different types of networks. You can also specifyconfig delay 1000
to introduce a 1000ms delay. See the manpage for more options.You can continue to reconfigure the pipe after adding the rule for it. For instance, to simulate nearing the edge of cellular coverage, issue this command while your app is running and connected (95% packet loss):
There is no need to run
sudo ipfw add 10 …
again after reconfiguring the pipe. You can script these changes to simulate an extremely dynamic network environment.Cleaning up
You can issue
sudo ipfw delete 10
to put everything back to normal, or just reboot.这是我在 OS X 上使用的一个很棒的脚本,用于限制您想要的任何域的连接速度,或者只是将其关闭。我希望我能记得我从哪里得到它以给予认可。
将代码保存到计算机上的文件中,并将其命名为“throttting”。然后要运行,只需在终端中输入以下内容,然后选择以下速度之一:
[full|fast|medium|slow|wwdc|off]
。如果您将脚本设置为限制 localhost:3000 和 stackoverflow.com,那么从浏览器(或 iPhone 模拟器或其他设备)中的任何一个域加载页面的响应速度和加载文件速度都会变慢。它对于测试 iphone 连接错误来说真的很棒。
http://gist.github.com/499177
Here is a great script I've used on OS X to throttle connection speed, or just turn it off, for any domain you want. I wish I could remember where I got it from to give credit.
Save the code to a file on your machine and name it "throttling". Then to run, just enter the below in terminal, and select from one of these speeds:
[full|fast|medium|slow|wwdc|off]
.If you have the script set up to throttle localhost:3000 and stackoverflow.com, then loading up a page from either of those domains in your browser (or iphone simulator or whatever) will respond slower and load files slower. It's been really great for testing iphone connectivity bugs.
http://gist.github.com/499177
如果您关闭 3G 并连接到 WiFi,您可以测试很多东西。
登录您的路由器并对您的 iPhone 的 MAC 地址进行速率限制。 (测试慢速连接)
下载数据时关闭 wifi 电源
下载时重新启动 wifi 路由器,以便手机有连接,失去连接,然后再次连接。 (测试不同的场景)
快乐编码!
You could test a number of things if you turn 3G off and connect to wifi.
Log into your router and rate limit the mac address of your iphone. (to test slow connections)
Kill the power to the wifi when in the middle of downloading data
Reboot the wifi router when downloading so the phone has connection, loses it, and gets it again. ( to test different scenarios )
Happy Coding!
我读到有人用 USB 线连接 iPhone 并用铝箔包裹手机进行测试,以减少蜂窝信号。您可以关闭 WiFi 和 3G,只使用 Edge,然后用箔片对其进行衰减。听起来很粗糙,但是...
您也可以使用 iPhone 4 并将其握在手中,将两个天线短接在一起;-)
I read of someone testing with their iPhone connected by USB cable and the phone wrapped in aluminum foil to get the cellular signal reduced. You can turn off WiFi and 3G and just have Edge and then attenuate it with foil. Sounds crude but...
You could also use an iPhone 4 and hold in your hand to short the two antennas together ;-)
Chrome 38 在设备模拟设置中包含网络模拟。您可以选择离线、GPRS、EDGE、3G、DSL 和 WiFi。还模拟增加的延迟。
它不如在真实设备上测试那么准确,但设置速度要快得多。
Chrome 38 includes network emulation in the device emulation settings. You can select from Offline, GPRS, EDGE, 3G, DSL and WiFi. Also emulates increased latency.
It's not as accurate as testing on a real device but it's much quicker to set up.
嗯,低带宽很简单:关闭Wifi,关闭3G。切断连接也很简单:打开 wifi,建立连接,关闭 wifi 接入点。
Well, low bandwidth is simple: turn off Wifi, turn off 3G. Cutting connection is also simple: turn on wifi, get connected, power off your wifi access point.
我想你可以连接到一台 Mac(如果你有的话)设置为 WiFi 基站(ad-hoc 网络)。然后在 Mac 上设置“虚拟网络”带宽限制和/或高丢包过滤器。
这就是我用来模拟速度较慢、延迟较高的 DSL 线路的方法,我正在制作用于 Mac 的设置软件。
I guess you could connect to a Mac (if you had one) setup as a WiFi base station (ad-hoc network). Then on the Mac set up a "dummynet" bandwidth limit and/or high packet loss filter.
That's what I do to simulate the slower higher-latency DSL lines I am making software to setup for Macs.
在 iPhone 上则不能。一种方法是将您的计算机 WIFI 连接共享到您的 iPhone,但使用特殊的应用程序来减慢速度。
这篇博文描述了一些方法:
http://blog.aptivate.org/2010/01/23/make-sure-your-apps-work-in-the-field/
On the iPhone you can't. One way would be to share your computer WIFI connection to your iPhone but to slow it down using a special application.
This blog post describes some approaches for that:
http://blog.aptivate.org/2010/01/23/make-sure-your-apps-work-in-the-field/