|
| 1 | +--- |
| 2 | +title: Simulate Poor Network Conditions |
| 3 | +slug: en/docs/tutorials/simulate-poor-network |
| 4 | +sidebar: |
| 5 | + order: 4 |
| 6 | +--- |
| 7 | + |
| 8 | +This guide explains how to use the staged toxic proxy setup to simulate poor network conditions when developing Open Data Capture. |
| 9 | + |
| 10 | +When you run `scripts/toxic-proxy.sh`, it configures Toxiproxy with the following simulated network conditions: |
| 11 | + |
| 12 | +- **Downstream bandwidth limit (API → browser):** capped at **5,000 bytes/second** (~5 KB/s). |
| 13 | +- **Upstream bandwidth limit (browser → API):** capped at **2,500 bytes/second** (~2.5 KB/s). |
| 14 | +- **Intermittent latency and jitter (downstream):** |
| 15 | + - Base latency of **50 ms**, plus up to **500 ms of jitter**. |
| 16 | + - Applied with **20% toxicity**, meaning only about 1 in 5 downstream requests/responses are delayed in this way. |
| 17 | +- **Occasional random connection resets (downstream):** |
| 18 | + - Connections are **randomly reset/closed** from the proxy side. |
| 19 | + - Applied with **10% toxicity**, so roughly 1 in 10 downstream connections will be abruptly terminated. |
| 20 | + |
| 21 | +Together, these toxics approximate a slow, unstable network where responses arrive slowly, some requests suffer extra delay, and a minority of connections fail unexpectedly. |
| 22 | + |
| 23 | +### Prerequisites |
| 24 | + |
| 25 | +- Install Toxiproxy (both `toxiproxy-server` and `toxiproxy-cli`) and ensure they are available on your `PATH`. |
| 26 | + |
| 27 | +### Steps |
| 28 | + |
| 29 | +<Steps> |
| 30 | + |
| 31 | +1. **Set the toxic proxy port in `.env`** |
| 32 | + |
| 33 | + Choose a port for the toxic proxy (for example `5501`) and set: |
| 34 | + - `API_DEV_TOXIC_PROXY_PORT=5501` |
| 35 | + |
| 36 | +2. **Point the frontend at the toxic proxy** |
| 37 | + |
| 38 | + Update `API_BASE_URL` to use the same port on localhost: |
| 39 | + - `API_BASE_URL=http://localhost:5501` |
| 40 | + |
| 41 | +3. **Start the toxic proxy** |
| 42 | + |
| 43 | + Run: |
| 44 | + |
| 45 | + ```bash |
| 46 | + scripts/toxic-proxy.sh |
| 47 | + ``` |
| 48 | + |
| 49 | + Leave this running. It creates a proxy that sits between the frontend and the API server and applies bandwidth limits. |
| 50 | + |
| 51 | +4. **Launch the app as normal** |
| 52 | + |
| 53 | + In another terminal, run: |
| 54 | + |
| 55 | + ```bash |
| 56 | + pnpm dev |
| 57 | + ``` |
| 58 | + |
| 59 | +</Steps> |
| 60 | + |
| 61 | +### Notes |
| 62 | + |
| 63 | +- The proxy reads `API_DEV_SERVER_PORT` from `.env` to know where your API server is listening. |
| 64 | +- If `API_DEV_TOXIC_PROXY_PORT` is empty, the script exits without starting the proxy. |
0 commit comments