Documentation / Connectivity

Connectivity

Change/set connectivity

You can and should throttle the connection to make the connectivity slower, which makes it easier to catch regressions. If you don't, your tests will run with different connectivity profiles and any regressions/improvements you see may just be caused by your server's flaky internet connection.

The best way to do that is to use our connectivity engine Throttle, set up a network bridge in Docker, or use Humble (the Raspberry Pi WiFi network link conditioner) if you test with mobile phones.

Throttle

Throttle uses tc on Linux and pfctl on Mac to change the connectivity. Throttle needs sudo rights for the user running sitespeed.io to work.

To use Throttle, set the connectivity engine with --connectivity.engine throttle.

browsertime --connectivity.engine throttle -c cable https://www.sitespeed.io/

or for sitespeed.io:

sitespeed.io --browsertime.connectivity.engine throttle -c cable https://www.sitespeed.io/

You can also use Throttle inside Docker, but then the host needs to be the same OS as in Docker. In practice you can only use it on Linux. And then make sure to run sudo modprobe ifb numifbs=1 first and give the container the right privileges --cap-add=NET_ADMIN.

First use modprobe:

sudo modprobe ifb numifbs=1

Then make sure you use the right privileges:

docker run --cap-add=NET_ADMIN --rm sitespeedio/sitespeed.io:41.0.1 -c 3g --browsertime.connectivity.engine=throttle https://www.sitespeed.io/

If you run Docker on OS X, you need to throttle outside of Docker. Install it and run like this:

# First install
$ npm install @sitespeed.io/throttle -g

# Then set the connectivity, run and stop
$ throttle cable
$ docker run --shm-size=1g --rm sitespeedio/sitespeed.io:41.0.1 https://www.sitespeed.io/
$ throttle stop

Humble (for mobile phone testing)

To get Humble up and running you need a Raspberry Pi 4. The Pi will share a throttled WiFi network that you can use from your phone. Browsertime/sitespeed.io will connect to the Raspberry Pi and configure the connectivity on the WiFi before your test starts.

  1. Follow the instructions to set up the Raspberry Pi WiFi network.
  2. Make sure your phone uses the new WiFi (named humble by default).
  3. Run the tests!

To make sure sitespeed.io sets the connectivity you need to set the engine to humble and set the URL to the Raspberry Pi:

sitespeed.io --browsertime.connectivity.engine=humble --browsertime.connectivity.humble.url=http://raspberrypi.local:3001 --android --browsertime.connectivity.profile 3g https://www.sitespeed.io  

Docker networks

Here's a full example for setting up Docker network bridges on a server that has tc installed:

#!/bin/bash
echo 'Starting Docker networks'
docker network create --driver bridge --subnet=192.168.33.0/24 --gateway=192.168.33.10 --opt "com.docker.network.bridge.name"="docker1" 3g
tc qdisc add dev docker1 root handle 1: htb default 12
tc class add dev docker1 parent 1:1 classid 1:12 htb rate 1.6mbit ceil 1.6mbit
tc qdisc add dev docker1 parent 1:12 netem delay 150ms

docker network create --driver bridge --subnet=192.168.34.0/24 --gateway=192.168.34.10 --opt "com.docker.network.bridge.name"="docker2" cable
tc qdisc add dev docker2 root handle 1: htb default 12
tc class add dev docker2 parent 1:1 classid 1:12 htb rate 5mbit ceil 5mbit
tc qdisc add dev docker2 parent 1:12 netem delay 14ms

docker network create --driver bridge --subnet=192.168.35.0/24 --gateway=192.168.35.10 --opt "com.docker.network.bridge.name"="docker3" 3gfast
tc qdisc add dev docker3 root handle 1: htb default 12
tc class add dev docker3 parent 1:1 classid 1:12 htb rate 1.6mbit ceil 1.6mbit
tc qdisc add dev docker3 parent 1:12 netem delay 75ms

docker network create --driver bridge --subnet=192.168.36.0/24 --gateway=192.168.36.10 --opt "com.docker.network.bridge.name"="docker4" 3gslow
tc qdisc add dev docker4 root handle 1: htb default 12
tc class add dev docker4 parent 1:1 classid 1:12 htb rate 0.4mbit ceil 0.4mbit
tc qdisc add dev docker4 parent 1:12 netem delay 200ms

When you run your container, you add the network with --network cable. A full example running with cable:

docker run --shm-size=1g --network=cable --rm sitespeedio/sitespeed.io:41.0.1 -c cable https://www.sitespeed.io/

And using the 3g network:

docker run --shm-size=1g --network=3g --rm sitespeedio/sitespeed.io:41.0.1 -c 3g https://www.sitespeed.io/

And if you want to remove the networks:

#!/bin/bash
echo 'Stopping Docker networks'
docker network rm 3g
docker network rm 3gfast
docker network rm 3gslow
docker network rm cable