npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sitespeed.io/throttle

v5.0.1

Published

Throttle your connection

Downloads

20,354

Readme

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.