%%
date:: [[2021-04-01]], [[2020-12-08]], [[2022-10-25]]
%%
# [[Network bandwidth throttling]]
Throttling [[Network bandwidth]] is a technique used in [[Load Testing]] and [[Performance Testing]] to set a limit on the network bandwidth or speed with which requests and responses are sent between a load generator and the application under test.
Applying this technique simulates a real user's experience interacting with an application, taking into account slower DSL or mobile network speeds.
Not accounting for this difference in speeds may lead to overestimations of actual end user response times.
## Approaches for throttling in testing
### Automate real mobile devices on mobile networks
The most realistic way, since it's not actually a simulation, but it's also the most unwieldy and expensive.
A provider with a device farm, such as [[Sauce Labs]], is likely required.
### Restrict bps through browser
Throttle the bandwidth on the browser side and use a tool that drives the browser to generate load.
[[Network bandwidth throttling in Puppeteer]] uses this approach via [[Chrome DevTools]].
### Limit characters per second sent and received
Use characters per second (cps) to approximate bps and limit the cps that is sent or processed.
[[Network bandwidth throttling in JMeter]] uses this approach, converting network speeds to cps instead of bps. I'm unsure if JMeter's implementation limits the cps that is processed (response) as well as what's sent.
### Run traffic through a [[Proxy Server]] that limits throughput
Many proxies, like [[Fiddler]], allow you to throttle traffic that is routed through it in this way.
> This could be done by something like [mitmproxy](https://github.com/KevCui/mitm-scripts) or [muxy](https://github.com/mefellows/muxy). - [[Ivan Mirić]] on [GitHub issue](https://github.com/loadimpact/k6/issues/1098)
This is effective but it does require the setup and deployment of another tool.
Disadvantage: Proxies may not be able to simulate a mix of network conditions, since they typically just limit all traffic routed through them.
> with a proxy, it will be difficult to emulate, say, 80% of VUs having broadband connections, 10% having a good mobile connection and 10% having a spotty 2G connection or something like that - [[Nedyalko Andreev]] on [GitHub issue](https://github.com/loadimpact/k6/issues/1098)
### Restrict through script
Instead of throttling the network, throttle the number of requests that are sent by the [[Load Testing Tool]]. Most tools already do this as a way to customize load profiles. Setting a maximum throughput of requests will simulate a ceiling.
- [[Network bandwidth throttling in Gatling]]
- [[k6 Ramping Arrival Rate Executor]]
Disadvantage: this approach simulates the upload speed, but not the download speed. Requests are throttled, but the responses will still be received at the normal rate. This means that response times are still not going to reflect the return leg of information.