Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ This is useful if you test a local web server or run [WebPageReplay](https://git
throttle --rtt 200 --localhost
```

On Linux, throttle also sets the MTU of the loopback interface to 1500, the packet size of real networks. With the loopback default (65536), the receive window of the browser limits the transfer, and the number of round trips changes from run to run. Stop sets the MTU back to 65536. If you do this on a host and not in a container, all local traffic uses the smaller packets until you stop.

## Stop adding delay on localhost

```
Expand Down
8 changes: 8 additions & 0 deletions lib/localHostTc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sudo from './sudo.js';

// Real networks use 1500-byte packets. With the loopback default (65536),
// the receive window of the browser limits the transfer, and the number of
// round trips changes from run to run.
const NETWORK_MTU = '1500';
const LOOPBACK_DEFAULT_MTU = '65536';

export async function start(delay) {
const halfWayDelay = delay / 2;

Expand All @@ -22,7 +28,9 @@ export async function start(delay) {
'delay',
`${halfWayDelay}ms`
);
await sudo('ip', 'link', 'set', 'dev', 'lo', 'mtu', NETWORK_MTU);
}
export async function stop() {
await sudo('ip', 'link', 'set', 'dev', 'lo', 'mtu', LOOPBACK_DEFAULT_MTU);
await sudo('tc', 'qdisc', 'del', 'dev', 'lo', 'root');
}
8 changes: 7 additions & 1 deletion test/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ tc qdisc del dev "$INTERFACE" clsact
## Same thing when a plain ingress qdisc already exists
tc qdisc add dev "$INTERFACE" ingress
bin/index.js --profile cable
bin/index.js --stop
bin/index.js --stop

## Localhost sets a real network MTU and stop restores the loopback default
bin/index.js --rtt 200 --localhost
ip link show lo | grep -q 'mtu 1500'
bin/index.js --stop --localhost
ip link show lo | grep -q 'mtu 65536'
Loading