Fiddler packet capture tool usage guide: Weak network environment simulation speed limit test process

One: Why do weak network testing?

The actual customer site may have unstable network or low network speed. The bad network environment will cause some bugs, affect the user experience and even some services are unavailable. However, the internal R&D environment network of the company is usually smooth, and it is difficult to reproduce this kind of bug. To solve this problem, it is necessary to create a weak network environment to test, reproduce and fix the problem.

2: How to simulate a harsh network environment?

This article only takes fiddler as an example, and the others will be understood without specific research.

Three: How does Fiddler simulate a weak network?

Fiddler is an HTTP debugging proxy that records all HTTP traffic between your computer and the Internet. Fiddler also lets you inspect all HTTP traffic, set breakpoints, and modify all "in and out" data (referring to cookies/HTML /JS/CSS etc.).

Using Fiddler to simulate a harsh network environment is simple and intuitive. The disadvantage is that it can only support those services that use HTTP for communication and interaction.

  • Open fiddler. By default, Rules –> Performances –> Simulate Modem Speeds is unchecked, and the network is normal. When this option is selected (simulate light cat network speed), the network speed will become very slow, and it will take a long time to load a web page. This achieves the weak network effect.

 

set up

If you want to know the specific value of the network speed (upload and download), you can use a tool speedtest, the speed measurement method is very simple, and there are a lot of tutorials on the Internet.

http://www.speedtest.net/ is an English website, it should be a foreign version, and the access is relatively slow. And the Windows system only supports the Windows 10 download client. I use Windows 7 to use the chrome browser to install the Speedtest extension, so it is not recommended to use it. It is recommended to visit the http://www.speedtest.cn/ website, the speed test results are very fast and in Chinese. Support mobile client APP download.

Four: The principle of speed limit

The Fiddler speed limit is implemented in the form of network delay, network delay time * network speed = number of bytes transmitted.

  • Click Rules – Customize Rules (shortcut Ctrl + R) to open the Fiddler ScriptEditor, or directly click on the FiddlerScript on the home page tab on the right.

 

image.png

  • After opening the file, Ctrl + F to find the m_SimulateModem flag, you can see the following code:

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

Note:  request-trickle-delayThe value in represents how many milliseconds each KB of data will be delayed when it is uploaded; response-trickle-delayit corresponds to how many milliseconds each KB of data will be delayed when it is downloaded. For example, if you want to simulate a network with an upload speed of 100KBps, the upload delay is 1KB/100KBps=0.01s=100ms, so change it to 100.

When Simulate Modem Speeds is checked, request-trickle-delay 与 response-trickle-delayit will be set. If the network speed is already quite fast, the value set here can approximate the upload and download bandwidth after the simulation is turned on, such as the upload delay under the default setting. The download delay is 150ms for 300ms, and the approximate analog bandwidth can be calculated as:

Upload bandwidth = (1 * 8/1000) /0.300 ≈ 0.027Mbps

Download bandwidth = (1 * 8/1000) /0.150 ≈ 0.053Mbps

There may be errors in the actual bandwidth obtained, and it will not be so accurate due to various external factors.

It can be seen that the download bandwidth is twice that of the upload, that is, the smaller the delay, the greater the bandwidth. The bandwidth and the delay here are inversely proportional.

Five: Adjust the network environment parameters

Fiddler's default Simulate Modem Speeds is too slow, and this speed limit parameter can be adjusted. If you need to go faster, you can modify the configuration file Fiddler2ScriptsCustomRules.js. (If you modify it, don't forget to back up the original file) You can find reference examples on the fiddler official website http://www.fiddlerbook.com/Fiddler/dev/ScriptSamples.asp.

The following provides two simple ways to modify the script, choose one.

  • method 1

Find the if (m_SimulateModem) statement and modify the code. The following script implements a random delay setting, so that the network bandwidth is not constant at a low speed value, but randomly jitters 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);}
  • Method 2

Click on fiddlerScript to find onBeforeRequest in the code, which defines what to do before sending the request. The delay can be achieved by adding the following code:

oSession["request-trickle-delay"]="3000"; //The request phase is delayed by 3 seconds oSession["response-trickle-delay"]="3000"; //The response phase is delayed by 3 seconds

 

add code

Choose one of the above two methods, save the configuration file after modification (Ctrl+S) or clear the cache (Rules –> Performances –>Disable Caching), and check the Rules –> Performances –> Simulate Modem Speeds again for speed measurement. Note: After editing and saving the configuration file, the Simulate Modem Speeds option will be canceled, please check it again.

The speed limit must be unchecked, otherwise it will affect the Internet access. Like the second method, because the request and response are delayed by 3 seconds, it will cause slow access to the web page.

 

 

Reprinted to: Public Account of Software Testing Resource Station

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325253404&siteId=291194637