• Stars
    star
    332
  • Rank 126,957 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Throttle your network connection [Linux/Mac OS X]

Simulate slow network connections on Linux and Mac OS X

Linux OSX Docker

Inspired by tylertreat/Comcast, the connectivity setting in the WPTAgent and sltc.

Throttle uses pfctl on Mac and tc on Linux to simulate different network speeds. On Linux you also need ip for Throttle to work (install using sudo apt-get install -y net-tools).

You can set the download/upload speed and/or RTT. Upload/download is in kbit/s and RTT in ms.

Use with latest NodeJS LTS.

Install

npm install @sitespeed.io/throttle -g

On OSX, add these lines to /etc/pf.conf if they don't exist, to prevent the pfctl: Syntax error in config file: pf rules not loaded error when you try to run throttle

pf_enable="YES"
pflog_enable="YES"

On Linux you need to make sure ip and route is installed (install using sudo apt-get install -y net-tools).

Start simulate a slower network connection

Here is an example for running with 3G connectivity. Remember: Throttle will use sudo so your user will need sudo rights.

throttle --up 330 --down 780 --rtt 200

Pre made profiles

To make it easier we have pre made profiles, check them out by throttle --help:

--profile         Premade profiles, set to one of the following
                     3g: up:768 down:1600 rtt:150
                     3gfast: up:768 down:1600 rtt:75
                     3gslow: up:400 down:400 rtt:200
                     2g: up:256 down:280 rtt:400
                     cable: up:1000 down:5000 rtt:14
                     dsl: up:384 down:1500 rtt:14
                     3gem: up:400 down:400 rtt:200
                     4g: up:9000 down:9000 rtt:85
                     lte: up:12000 down:12000 rtt:35
                     edge: up:200 down:240 rtt:35
                     dial: up:30 down:49 rtt:60
                     fois: up:5000 down:20000 rtt:2

You can start throttle with one of the premade profiles:

throttle --profile 3gslow

or even simpler

throttle 3gslow

Add packet loss

By default there's no packet loss. That is by design: If you want to use Throttle and have the same network speed, packet loss is no good. However if you want to simalate a really crappy network you probably want to add packet loss. You do that with the --packetLoss option. You set the packet loss in percent.

throttle --profile 3gslow --packetLoss 5

Use a configuration file

You can also use a configuration file with your settings. Use --config to map your config file to throttle.

config.json

{
    "up": 330 ,
    "down": 200,
    "rtt": 1000
}

And then run:

throttle --config config.json

Stop simulate the network

Stopping is as easy as giving the parameter stop to throttle.

throttle --stop

or

throttle stop

Add delay on your localhost

This is useful if you test a local web server or run WebPageReplay and want to add some latency to your tests.

throttle --rtt 200 --localhost

Stop adding delay on localhost

throttle --stop --localhost

Use directly in NodeJS

import throttle from '@sitespeed.io/throttle'
// Returns a promise
throttle.start({up: 360, down: 780, rtt: 200}).then(() => ...

or

import throttle from '@sitespeed.io/throttle'
// Returns a promise
const options = {up: 360, down: 780, rtt: 200};
await throttle.start(options);
// Do your thing and then stop
await throttle.stop();

Log all commands

You can log all the commands that sets up the throttling by setting LOG_THROTTLE=true.

LOG_THROTTLE=true throttle 3gslow

or

throttle 3gslow --log

Run in Docker (on Linux)

Make sure to run sudo modprobe ifb numifbs=1 before you start the container.

And then when you actually start your Docker container, give it the right privileges with --cap-add=NET_ADMIN.

More Repositories

1

sitespeed.io

sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your websiteโ€™s speed using real browsers in various environments.
JavaScript
4,716
star
2

coach

Clear Eyes. Full Hearts. Canโ€™t Lose.
JavaScript
1,204
star
3

browsertime

Measure and Optimize Web Performance
JavaScript
602
star
4

chrome-har

Create HAR files from Chrome Debugging Protocol data
JavaScript
138
star
5

compare

Compare HAR files.
JavaScript
110
star
6

pagexray

Xray your HAR file and know all about the page
JavaScript
83
star
7

grafana-bootstrap-docker

Shell
60
star
8

sitespeed.io-docker

Shell
52
star
9

dashboard.sitespeed.io

Example how to use sitespeed.io to monitor the performance of your web site
JavaScript
45
star
10

jenkins.sitespeed.io

A Jenkins plugin for sitespeed.io
Java
31
star
11

grunt-sitespeedio

Test performance budgets and performance best practice rules using sitespeed.io
JavaScript
28
star
12

plugin-lighthouse

Lighthouse plugin for sitespeed.io
JavaScript
26
star
13

chrome-trace

Process Chrome trace logs in Node.
JavaScript
14
star
14

plugins

List of 3rd party plugins for sitespeed.io
10
star
15

run.sitespeed.io

Online version of sitespeed.io
JavaScript
9
star
16

docker-browsers

Dockerfile
8
star
17

plugin-gpsi

GPSI plugin for sitespeed.io
JavaScript
7
star
18

humble

Raspberry Pi WiFi network link conditioner
6
star
19

plugin-third-party-decode

Run Paul Irish Third Party Decode library to categorise third parties
JavaScript
5
star
20

chromedriver

Install and launch Chromedriver for Mac, Linux or Windows.
JavaScript
4
star
21

sltc

JavaScript
4
star
22

browsertime-extension

Extension that runs in Firefox/Chrome to get some extra fire for Browsertime
JavaScript
3
star
23

logo

All the logos for sitespeed.io
3
star
24

plugin-webpagetest

sitespeed.io plugin for running WebPageTest
JavaScript
2
star
25

travis

Example repo for using sitespeed.io budget using Travis
HTML
2
star
26

docker-node

Base Docker container for sitespeed.io with Ubuntu & NodeJS
Dockerfile
1
star
27

raspberrypi

Pre-made raspberry pi image to drive Android phones
1
star
28

geckodriver

Install and launch Geckodriver for Mac, Linux or Windows.
JavaScript
1
star