From d4edbc0959d5b816597d1e62004776301ef73875 Mon Sep 17 00:00:00 2001 From: yinjie <2285342783@qq.com> Date: Mon, 23 Mar 2015 17:45:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?wingjay=20=E7=BF=BB=E8=AF=91=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...when-testing-on-mobile-devices-[wingjay].md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sources/Issue#103/Simulating-a-slow-network-connection-when-testing-on-mobile-devices-[wingjay].md b/sources/Issue#103/Simulating-a-slow-network-connection-when-testing-on-mobile-devices-[wingjay].md index b2787e5..7c8a169 100644 --- a/sources/Issue#103/Simulating-a-slow-network-connection-when-testing-on-mobile-devices-[wingjay].md +++ b/sources/Issue#103/Simulating-a-slow-network-connection-when-testing-on-mobile-devices-[wingjay].md @@ -6,15 +6,13 @@ comments: true categories: 移动设备 模拟慢速网络 测试 --- -移动设备的网络连接通常不太稳定-比如在农村,坐在地铁上或车里都会发生连接问题。所以移动原生应用或移动web应用必须考虑慢速网络,同时尽量减轻网络请求超时或长时间响应给用户带来的不满。为了模拟慢速连接,在大多数模拟器上你可以通过设置网络参数(对于安卓设备可以参考(http://developer.android.com/tools/devices/emulator.html#netdelay)),或者使用一个工具-Charles proxy(http://www.charlesproxy.com/)。 +移动设备的网络连接通常不太稳定-比如在农村,坐在地铁上或车里都会发生连接问题。所以移动原生应用或移动web应用必须考虑慢速网络,同时尽量减轻网络请求超时或长时间响应给用户带来的不满。为了模拟慢速连接,在大多数模拟器上你可以通过设置网络参数(对于安卓设备可以参考[这里](http://developer.android.com/tools/devices/emulator.html#netdelay)),或者使用一个工具-[Charles proxy](http://www.charlesproxy.com/)。 但这在实际物理设备上不管用。这主要用于真实环境下的不同设备和平台。 +通过无线路由器,我们可以使用linux流量整形(Linux traffic shaping)来增加延时,减缓通信吞吐速度并随机丢弃数据包。在这个例子中我使用了OpenWRT因为我比较熟悉,而且[OpenWRT支持很多路由器](http://wiki.openwrt.org/toh/start),不过DD-WRT也同样有用。首先要有一个支持的路由器和一个[不稳定Barrier Breaker镜像](http://downloads.openwrt.org/snapshots/trunk/)。flash 它然后安装你的wifi。最后因为我并不需要路由,所以我将wifi连接到WAN口。 +[参考图片](http://awcntt-article-image.qiniudn.com/issue103_tumblr_inline_n619bwxsBm1qcsghp.png) -Using a wireless router we can use Linux traffic shaping to add delay, slow down the throughput and also randomly drop packets. For this example I used OpenWRT because I’m familiar with it and because it has a long list of [supported routers](http://wiki.openwrt.org/toh/start), but DD-WRT might work too. Get a supported router and a [snapshot](http://downloads.openwrt.org/snapshots/trunk/) image of the unstable Barrier Breaker release for the router. Flash it and set up your wifi. I ended up bridging the wifi to the WAN port since I did not need any routing: - -![image](http://awcntt-article-image.qiniudn.com/issue103_tumblr_inline_n619bwxsBm1qcsghp.png) - -Next, I created a shell script called qos.sh in /root: +然后,我在 /root 目录下创建一个脚本 qos.sh: ``` shell #!/bin/sh @@ -65,19 +63,19 @@ Next, I created a shell script called qos.sh in /root: tc qdisc add dev $WAN parent 2:12 netem delay $LATENCY 10ms 25% loss $LOSS ``` - -You can download it from [this gist](https://gist.github.com/unverbraucht/118117ab66ac142f4eda). Mark it as executable with chmod a+x qos.sh and add the following to /etc/rc.local before the exit statement: +你可以从[这里](https://gist.github.com/unverbraucht/118117ab66ac142f4eda)下载脚本文件。 +使用chmod a+x qos.sh命令将它转换为可执行文件并且在退出前,将下面的代码加入/etc/rc.local中: /root/qos.sh -The delay and packet loss in one direction could probably be eliminated. Bandwidth limiting needs to be applied in both directions though. The script is based on this [StackExchange answer](http://superuser.com/a/147434). More info on netem can be found on this [OpenWRT wiki page](http://wiki.openwrt.org/doc/howto/packet.scheduler/sch_netem). +单向的延时和丢包可能会被终止,我们应该在双向都进行带宽限制。这里的脚本是基于[StackExchange 回答](http://superuser.com/a/147434)。你可以在[OpenWRT 维基百科页面](http://wiki.openwrt.org/doc/howto/packet.scheduler/sch_netem)查看更多关于netem信息。 --- 原文地址:[http://kevin-read.com/post/86601925386/simulating-a-slow-network-connection-when-testing-on](http://kevin-read.com/post/86601925386/simulating-a-slow-network-connection-when-testing-on) -译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID) +译者:[wingjay](https://github.com/wingjay) 校对:[校对者ID](https://github.com/校对者ID) 本文由[AWCNTT](https://github.com/AWCNTT) 原创翻译,[AndroidWeekly中国](http://www.androidweekly.cn/) 荣誉推出 From bc9f0cc255bc01392b40032de460dec045fbfbed Mon Sep 17 00:00:00 2001 From: yinjie <2285342783@qq.com> Date: Mon, 23 Mar 2015 23:08:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=EF=BC=BB=E7=BF=BB=E8=AF=91=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=BDIssue#103=20Simulating-a-slow-network-connect?= =?UTF-8?q?ion-when-testing-on-mobile-devices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nnection-when-testing-on-mobile-devices.md | 82 +++++++++++++++++++ translated/Issue#103/Issue#103.md | 2 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 translated/Issue#103/2015-3-23-Simulating-a-slow-network-connection-when-testing-on-mobile-devices.md diff --git a/translated/Issue#103/2015-3-23-Simulating-a-slow-network-connection-when-testing-on-mobile-devices.md b/translated/Issue#103/2015-3-23-Simulating-a-slow-network-connection-when-testing-on-mobile-devices.md new file mode 100644 index 0000000..7c8a169 --- /dev/null +++ b/translated/Issue#103/2015-3-23-Simulating-a-slow-network-connection-when-testing-on-mobile-devices.md @@ -0,0 +1,82 @@ +--- +layout: post +title: "在移动设备上进行测试时模拟一个慢速网络连接" +date: 2015-03-22 23:30 +comments: true +categories: 移动设备 模拟慢速网络 测试 +--- + +移动设备的网络连接通常不太稳定-比如在农村,坐在地铁上或车里都会发生连接问题。所以移动原生应用或移动web应用必须考虑慢速网络,同时尽量减轻网络请求超时或长时间响应给用户带来的不满。为了模拟慢速连接,在大多数模拟器上你可以通过设置网络参数(对于安卓设备可以参考[这里](http://developer.android.com/tools/devices/emulator.html#netdelay)),或者使用一个工具-[Charles proxy](http://www.charlesproxy.com/)。 +但这在实际物理设备上不管用。这主要用于真实环境下的不同设备和平台。 + +通过无线路由器,我们可以使用linux流量整形(Linux traffic shaping)来增加延时,减缓通信吞吐速度并随机丢弃数据包。在这个例子中我使用了OpenWRT因为我比较熟悉,而且[OpenWRT支持很多路由器](http://wiki.openwrt.org/toh/start),不过DD-WRT也同样有用。首先要有一个支持的路由器和一个[不稳定Barrier Breaker镜像](http://downloads.openwrt.org/snapshots/trunk/)。flash 它然后安装你的wifi。最后因为我并不需要路由,所以我将wifi连接到WAN口。 +[参考图片](http://awcntt-article-image.qiniudn.com/issue103_tumblr_inline_n619bwxsBm1qcsghp.png) + +然后,我在 /root 目录下创建一个脚本 qos.sh: + +``` shell + #!/bin/sh + + # The bandwidth to simulate, here about 56kilobit per second. This is layer 2 bandwidth, so TCP/UDP and IP overhead will apply + + BW=”56kbps” + + # _Half_ the latency that we aim for. Since this applies to both the WAN port and Wi-Fi, the delay is applied twice, so this actually puts it at around 120+ms + + LATENCY=”60ms” + + # Chance of packet loss. Also applied to both interfaces, so it is 1%. + + LOSS=”0.5%” + + # The device name of your wifi device. + + WIFI=”wlan0” + + # The device name of your wan port + + WAN=”eth0.2” + + # Delete existing traffic control rules + + tc qdisc del root dev $WIFI + + tc qdisc del root dev $WAN + + # Create a basic tc rule for wifi + + tc qdisc add dev $WIFI root handle 1: htb default 12 + + # First apply the rate limiting through a HTC scheduler + + tc class add dev $WIFI parent 1:1 classid 1:12 htb rate $BW ceil $BW + + # Then apply the netem scheduler which handles delay and packet loss + + tc qdisc add dev $WIFI parent 1:12 netem delay $LATENCY 10ms 25% loss $LOSS + + # The same for WAN + + tc qdisc add dev $WAN root handle 2: htb default 12 + + tc class add dev $WAN parent 2:1 classid 2:12 htb rate $BW ceil $BW + + tc qdisc add dev $WAN parent 2:12 netem delay $LATENCY 10ms 25% loss $LOSS +``` +你可以从[这里](https://gist.github.com/unverbraucht/118117ab66ac142f4eda)下载脚本文件。 +使用chmod a+x qos.sh命令将它转换为可执行文件并且在退出前,将下面的代码加入/etc/rc.local中: + + /root/qos.sh + +单向的延时和丢包可能会被终止,我们应该在双向都进行带宽限制。这里的脚本是基于[StackExchange 回答](http://superuser.com/a/147434)。你可以在[OpenWRT 维基百科页面](http://wiki.openwrt.org/doc/howto/packet.scheduler/sch_netem)查看更多关于netem信息。 + +--- + + +原文地址:[http://kevin-read.com/post/86601925386/simulating-a-slow-network-connection-when-testing-on](http://kevin-read.com/post/86601925386/simulating-a-slow-network-connection-when-testing-on) + +译者:[wingjay](https://github.com/wingjay) 校对:[校对者ID](https://github.com/校对者ID) + +本文由[AWCNTT](https://github.com/AWCNTT) 原创翻译,[AndroidWeekly中国](http://www.androidweekly.cn/) 荣誉推出 + +版权声明:原创译文欢迎自由转载-非商用-非衍生-保持署名 | [Creative Commons BY-NC-ND 3.0](http://creativecommons.org/licenses/by-nc-nd/3.0/deed.zh) \ No newline at end of file diff --git a/translated/Issue#103/Issue#103.md b/translated/Issue#103/Issue#103.md index c04ccfe..fd4094d 100644 --- a/translated/Issue#103/Issue#103.md +++ b/translated/Issue#103/Issue#103.md @@ -17,7 +17,7 @@ categories: Issue#103 这是在Mac上构建AOSP系列文章中的第一篇。 -[**在移动设备上进行测试时模拟一个慢速网络连接**](http://kevin-read.com/post/86601925386/simulating-a-slow-network-connection-when-testing-on) (kevin-read.com) +[**在移动设备上进行测试时模拟一个慢速网络连接**](https://github.com/wingjay/ArticleTranslateProject/tree/master/translated/Issue%23103/2015-3-23-Simulating-a-slow-network-connection-when-testing-on-mobile-devices.md) 如果你想要在一个设备上模拟缓慢和参差不齐的网络连接,可以做到这一点的方法之一是通过在路由器上配置OpenWRT。