Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sitespeed.io/throttle

Package Overview
Dependencies
Maintainers
3
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sitespeed.io/throttle

Throttle your connection

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.8K
increased by44.13%
Maintainers
3
Weekly downloads
 
Created
Source

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 and route 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"

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

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 run WebPageReplay and want to add som latency to your tests.

throttle --rtt 200 --localhost

Stop adding delay on localhost

throttle --stop --localhost

Use directly in NodeJS

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

or

const throttle = require('@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.

Keywords

FAQs

Package last updated on 10 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc