Use Fiddler to simulate the network

Fiddler has been preset to provide the option of simulating Modem speed, its location is at: 
Rules->Performances->Simulate Modem Speeds 

If you want to learn the Fiddler packet capture tool, here I recommend a set of videos for you. This video can be said to be the No. 1 Fiddler packet capture tool tutorial on the Internet at station B. At the same time, the number of online users reaches 1,000, and there are notes available Receiving and technical exchanges with various masters

Play Fiddler packet capture with zero foundation and apply it in the field of testing! _哔哩哔哩_bilibili [Python interface automation test notes and video source code + WeChat: mashang-nn Remarks (555 at station b) can be collected for free, and three consecutive likes are the true love! 】, The number of video views is 1270, the number of bullet screens is 2, the number of likes is 4, the number of coins tossed is 2, the number of bookmarks is 20, and the number of reposts is 0. Station B 555, related videos: Fiddler packet capture tool is the most complete and detailed tutorial on the entire network, no one, the latest Jmeter interface test practical tutorial at station B in 2023, proficient in interface automation testing only needs this set of videos, station B benefits! Web automation testing from 0- to project actual combat tutorial, free to learn! ! ! , Play the four major applications of fiddler capture in the testing field from 0! , 2023 performance test nanny-level tutorial full set full version [jmeter performance test actual combat, jmeter performance test, jmeter stress test], Postman interface test usage tutorial + download + installation and project actual combat tutorial, from 0 to play with Fiddler to capture packets in the test field Four major applications in practice! , The latest version of Jmeter performance test project in 2023 is explained in practice, from entry to proficiency in the actual combat tutorial of 8888, Postman interface test is the best tutorial interface project actual combat you have everything you want, the interface test artifact: Apifox, how fragrant it is! https://www.bilibili.com/video/BV14g4y1H7vv/?spm_id_from=333.999.0.0
After checking this option, all the traffic proxied by Fiddler will become normal with a 56k modem. 
To visually observe the effect of the speed limit, it is best to use a speed test tool running in the browser. Here, it is recommended to use the "http://www.speedtest.cn/" online speed test tool for testing. 
Adjust parameters for simulating harsh network environments
Directly simulating the modem speed is really slow. In fact, even in the case of poor signal, the mobile network speed of the mobile phone has exceeded the modem speed of 56k, so the simulated environment with the default configuration does not necessarily meet the requirements. At this time, it is necessary to adjust the parameters of the speed limit. 
Fiddler itself provides a configuration file for adjusting these parameters, click: 
Rules – Customize Rules... 
to open the CustomRules.js file (Fiddler2Scripts located in the document directory of the user directory by default), the suffix is ​​js. Find the "m_SimulateModem" flag in the edit content:

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"; 
        }

This flag controls the setting of the two parameter values ​​of oSession. When Simulate Modem Speeds is checked, request-trickle-delay and response-trickle-delay will be set, where the value in request-trickle-delay represents each How many milliseconds will be delayed when KB data is uploaded, and response-trickle-delay corresponds to how many milliseconds will be delayed when downloading each KB of data. If the network speed is already quite fast, the value set here can be approximated The upload and download bandwidth after the simulation is turned on. For example, the download delay is 150ms by default, and the upload delay is 300ms. Correspondingly, the approximate analog bandwidth can be calculated as: upload bandwidth=(1*8/1000)
/0.300≈0.053 Mbps 
download bandwidth=(1*8/1000)/0.150≈0.027Mbps
Write a custom script
to further expand the logic in CustomRules.js. Refer to the Jscript documentation to add more custom logic in the simulated harsh environment. Here is the implementation A random delay is set, so that the network bandwidth is not constant at a low-speed value, but will jitter randomly within a certain range:

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(1,50);
    // Delay receives by 150ms per KB downloaded.
    oSession["response-trickle-delay"] = ""+randInt(1,50);
}

By further extending CutionRules.js, many required harsh environment simulation scenarios can be realized. If the scene is more complex, you can also write C# plug-in code to further control the behavior of Fiddler by writing Fiddler plug-ins. I won’t go into details here. up.
Limitations of Fiddler's simulation of harsh network environments
Fiddler's speed limit is relatively simple and flexible, and its configuration is more convenient. However, because it is an HTTP proxy at the application layer, it can only simulate the behavior on this layer. For some complex network layers Bad situations such as packet loss and retransmission cannot be simulated well, and the application of other protocols is not supported.

Guess you like

Origin blog.csdn.net/caixiangting/article/details/131211981