fiddler弱网测试设置(转载)

1、模拟弱网环境

打开Fiddler,Rules->Performance->勾选 Simulate Modem Speeds,勾选之后访问网站会发现网络慢了很多

2、Fiddler弱网的原理

Rules—>Cutomize Rules打开CustomRules.js 文档

在文件中搜索关键字,m_SimulateModem

1.

  1.  
       // Cause Fiddler to delay HTTP traffic to simulate typical 56k modem conditions
  2.  
        public static RulesOption("Simulate &Modem Speeds", "Per&formance")
  3.  
        var m_SimulateModem: boolean = false;

2.

  1.  
    if (m_SimulateModem) {
  2.  
                // Delay sends by 300ms per KB uploaded.
  3.  
                oSession["request-trickle-delay"] = "300";
  4.  
                // Delay receives by 150ms per KB downloaded.
  5.  
                oSession["response-trickle-delay"] = "150";
  6.  
            }

让我们来分析一下这几行代码:

  • 首先来判断m_SimulateModem是否为true,也就是是否设置了弱网模式。

  • 如果为弱网模式。则分析代码

  • oSession[“request-trickle-delay”] = “300”; 注释的也很明白,Delay sends by 300ms per KB uploaded.上传1KB需要300ms,

    转化一下上传速度:1Kb/0.3s = 10/3(KB/s),也就是 3.33kb/s ,到达2G网络标准。

  • 如果你想设置上传的速度为50KB/s,你则需要设置Delay 时间为 20ms

  • 同样的方法,也可以限制上传的速度,调整oSession[“response-trickle-delay”]即可。


网络 上行 下载
2G 2.7K 9.6K
3G 1.8M 7.2M
4G 50M 100M

所以得出:2G网络配置

  1.  
    if (m_SimulateModem) {
  2.  
                // Delay sends by 300ms per KB uploaded.
  3.  
                oSession["request-trickle-delay"] = "300";
  4.  
                // Delay receives by 150ms per KB downloaded.
  5.  
                oSession["response-trickle-delay"] = "150";
  6.  
            }

3G 网络配置,3G 应该是2G网络估值的1000倍速率,也就是上行和下载除去1000。

  1.  
    if (m_SimulateModem) {
  2.  
                // Delay sends by 300ms per KB uploaded.
  3.  
                oSession["request-trickle-delay"] = "0.3";
  4.  
                // Delay receives by 150ms per KB downloaded.
  5.  
                oSession["response-trickle-delay"] = "0.15";
  6.  
            }

4G网络配置,上行为3G的25倍,下载为15倍,放开延迟即可。

 

 

 

转载自:https://blog.csdn.net/weixin_38328865/article/details/105456006

 

 

第二篇的部分内容:

打开该文件后,Ctrl + F 查找m_SimulateModem标志位,可以看到如下代码

if (m_SimulateModem) {

// Delay sends by 300ms per KB uploaded.

oSession["request-trickle-delay"] = "300";

// Delay receives by 150ms per KB downloaded.

oSession["response-trickle-delay"] = "150";

}

注释说明:

request-trickle-delay中的值代表每KB的数据被上传时会被延时多少毫秒;

response-trickle-delay则对应下载时每KB的数据会被延时多少毫秒。

比如你要模拟上传速度100KBps的网络,那上传延迟就是1KB/100KBps=0.01s=10ms,就改成10

默认设置下上传延时为300ms下载延时为150ms,大致模拟出来的宽带如下:

上传带宽 = 1KB/300ms = (1 * 8/1000) /0.300 ≈ 0.027Mbps

下载带宽 = 1KB/150ms = (1 * 8/1000) /0.150 ≈ 0.053Mbps

(1MB = 1024 KB ≈ 1000 KB 为了运算简便就用了1000的倍数,忽略误差)

实际带宽是在计算所得的基础上乘2,至于原因,没有深究

上传带宽=((1*8/1000)/0.300)*2.0≈0.106Mbps

下载带宽=((1*8/1000)/0.150)*2.0≈0.053Mbps

假如我们要模拟2M左右的宽带((1* 8/1000)/ x )*2.0=2

if (m_SimulateModem) {

// Delay sends by 300ms per KB uploaded.

oSession["request-trickle-delay"] = "8";

// Delay receives by 150ms per KB downloaded.

oSession["response-trickle-delay"] = "8";

设置网络环境参数

1、查找到if (m_SimulateModem)语句,修改代码。模拟网络带宽不是恒定的一个低速的值,而是一定范围内随机抖动,下面的脚本实现了一个随机延时量设置,使得网络带宽不是恒定为一个低速的值。

static function randInt(min, max) {

return Math.round(Math.random()*(max-min)+min);

}

if (m_SimulateModem) {

// Delay sends by 300ms per KB uploaded.

oSession["request-trickle-delay"] = ""+randInt(100,200);

// Delay receives by 150ms per KB downloaded.

oSession["response-trickle-delay"] = ""+randInt(1,50);

}

2、在代码里找到onBeforeRequest,这里定义了在发送请求前做什么。加入如下代码可以实现延迟:

oSession["request-trickle-delay"]="3000"; //请求阶段延迟3秒

oSession["response-trickle-delay"]="3000"; //响应阶段延迟3秒

 

转载自:https://blog.csdn.net/weixin_39769183/article/details/112941857

 

posted @ 2021-02-24 14:35  吾言!  阅读(570)  评论(0编辑  收藏  举报