-
Install and Start Whistle: First, install Whistle on your machine. You can install it via npm:
shellnpm install -g whistleAfter installation, start Whistle:
shellw2 start -
Configure Proxy: Next, configure your operating system or browser to use a proxy so that all network requests route through Whistle. Typically, Whistle operates on
127.0.0.1:8899. -
Set Network Delay Rules: Open Whistle's management interface, typically accessed in a browser at
http://local.whistlejs.com/. In this interface, you can define various network simulation rules.For example, to simulate network latency, add the following rule in the Rules window:
shellexample.com delay://3000This rule ensures that all requests to
example.comvia Whistle are artificially delayed by 3000 milliseconds (3 seconds). -
Test and Verify: After configuration, test if the delay is applied by accessing the relevant website. Additionally, Whistle provides detailed logs and packet information to help you better understand network request specifics.
-
Advanced Usage: Whistle supports not only simulating network latency but also network packet loss, bandwidth limitations, and other complex network conditions. For instance, using
lose://100simulates a 100% packet loss rate, whilespeed://100krestricts bandwidth to 100kbps.
By following these steps, you can effectively simulate various slow network environments with Whistle to help developers optimize and improve application performance under different network conditions. This is particularly crucial when developing mobile applications and cross-border software, as users' network conditions can vary significantly.