• Stars
    star
    10,309
  • Rank 3,362 (Top 0.07 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated 7 months ago

Reviews

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

Repository Details

Simulating shitty network connections so you can build better systems.

Comcast

Testing distributed systems under hard failures like network partitions and instance termination is critical, but it's also important we test them under less catastrophic conditions because this is what they most often experience. Comcast is a tool designed to simulate common network problems like latency, bandwidth restrictions, and dropped/reordered/corrupted packets.

It works by wrapping up some system tools in a portable(ish) way. On BSD-derived systems such as OSX, we use tools like ipfw and pfctl to inject failure. On Linux, we use iptables and tc. Comcast is merely a thin wrapper around these controls. Windows support may be possible with wipfw or even the native network stack, but this has not yet been implemented in Comcast and may be at a later date.

Installation

$ go install github.com/tylertreat/comcast@latest

Usage

On Linux, Comcast supports several options: device, latency, target/default bandwidth, packet loss, protocol, and port number.

$ comcast --device=eth0 --latency=250 --target-bw=1000 --default-bw=1000000 --packet-loss=10% --target-addr=8.8.8.8,10.0.0.0/24 --target-proto=tcp,udp,icmp --target-port=80,22,1000:2000

On OSX, Comcast will check for pfctl support (as of Yosemite), which supports the same options as above. If pfctl is not available, it will use ipfw instead, which supports device, latency, target bandwidth, and packet-loss options.

On BSD (with ipfw), Comcast currently supports only: device, latency, target bandwidth, and packet loss.

$ comcast --device=eth0 --latency=250 --target-bw=1000 --packet-loss=10%

This will add 250ms of latency, limit bandwidth to 1Mbps, and drop 10% of packets to the targetted (on Linux) destination addresses using the specified protocols on the specified port numbers (slow lane). The default bandwidth specified will apply to all egress traffic (fast lane). To turn this off, run the following:

$ comcast --stop

By default, comcast will determine the system commands to execute, log them to stdout, and execute them. The --dry-run flag will skip execution.

I don't trust you, this code sucks, I hate Go, etc.

If you don't like running code that executes shell commands for you (despite it being open source, so you can read it and change the code) or want finer-grained control, you can run them directly instead. Read the man pages on these things for more details.

Linux

On Linux, you can use iptables to drop incoming and outgoing packets.

$ iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP
$ iptables -A OUTPUT -m statistic --mode random --probability 0.1 -j DROP

Alternatively, you can use tc which supports some additional options.

$ tc qdisc add dev eth0 root netem delay 50ms 20ms distribution normal
$ tc qdisc change dev eth0 root netem reorder 0.02 duplicate 0.05 corrupt 0.01

To reset:

$ tc qdisc del dev eth0 root netem

BSD/OSX

To shape traffic in BSD-derived systems, create an ipfw pipe and configure it. You can control incoming and outgoing traffic separately for any specific host or network.

$ ipfw add 1 pipe 1 ip from me to any
$ ipfw add 2 pipe 1 ip from any to me
$ ipfw pipe 1 config delay 500ms bw 1Mbit/s plr 0.1

To reset:

$ ipfw delete 1

Note: ipfw was removed in OSX Yosemite in favor of pfctl.

Network Condition Profiles

Here's a list of network conditions with values that you can plug into Comcast. Please add any more that you may come across.

Name Latency Bandwidth Packet-loss
GPRS (good) 500 50 2
EDGE (good) 300 250 1.5
3G/HSDPA (good) 250 750 1.5
DIAL-UP (good) 185 40 2
DSL (poor) 70 2000 2
DSL (good) 40 8000 0.5
WIFI (good) 40 30000 0.2
Starlink 20 - 2.5

More Repositories

1

BoomFilters

Probabilistic data structures for processing continuous, unbounded streams.
Go
1,594
star
2

chan

Pure C implementation of Go channels.
Shell
1,406
star
3

BigQuery-Python

Simple Python client for interacting with Google BigQuery.
Python
456
star
4

bench

A generic latency benchmarking library.
Go
310
star
5

Flotilla

Automated message queue orchestration for scaled-up benchmarking.
Go
236
star
6

mq-benchmarking

Performance benchmarks for various message queues.
Go
192
star
7

CS-Literature-of-the-Day

A curated list of computer science literature, updated daily.
164
star
8

go-benchmarks

A few miscellaneous Go microbenchmarks.
Go
147
star
9

fast-topic-matching

Messaging middleware topic matching implementations.
Go
75
star
10

nanomsg-service-discovery

Service-discovery pattern implemented with nanomsg.
Python
25
star
11

gatling

Minimal pub/sub message queue in C.
C
22
star
12

Zinc

Real-time distributed messaging and document synchronization.
Java
15
star
13

InverseBloomFilter

Concurrent inverse Bloom filter.
Go
13
star
14

PubSub-Python

Simple Python client for interacting with Google Cloud Pub/Sub.
Python
9
star
15

log-benchmarking

Benchmarking for distributed logs.
Go
9
star
16

OpenGL-Playground

Playing with OpenGL.
C
8
star
17

thrift-nats

Thrift RPC over NATS.
Go
8
star
18

go-fast

Material for 'So You Wanna Go Fast?' Strange Loop talk
Go
8
star
19

hdrhistogram-writer

API for writing HdrHistograms in a readable format consumable by http://hdrhistogram.github.io/HdrHistogram/plotFiles.html.
Go
7
star
20

go-zab

Go implementation of ZooKeeper Atomic Broadcast.
Go
7
star
21

Dalvik-Baksmali

Android library for disassembling DEX files using baksmali.
Java
7
star
22

nats-leader-election

Leader election implemented with Raft over NATS.
Go
6
star
23

httpmonitor

CLI tool for monitoring HTTP traffic.
Go
5
star
24

kaput.io

Laws of General Systemantics.
CSS
5
star
25

sync

Some basic synchronization primitives.
C
4
star
26

rdcss

RDCSS double-compare-single-swap.
Go
4
star
27

dockerfiles

Contain yourself.
Shell
3
star
28

gae-circleci-java

Example Java Spring app running on Google App Engine deployed from CircleCI.
Java
2
star
29

uthread

C
2
star
30

dexmaker

Java
2
star
31

gatling-gun

Go client for gatling broker.
Go
2
star
32

matchboxd

Replicated matchbox server (https://github.com/Workiva/matchbox)
Go
2
star
33

vessel

Fast, asynchronous client-server messaging.
Go
2
star
34

SQLAlchemyUtils

Useful utilities for working with SQLAlchemy.
Python
2
star
35

TrendBlotter

The world talks, we listen.
JavaScript
2
star
36

vessel.js

Vessel messaging client.
JavaScript
2
star
37

gaeutils

Useful utilities for working with Google App Engine.
Python
1
star
38

crapchat

A janky and obnoxious chat application.
Go
1
star
39

Jockey

Seamless Google App Engine authentication for Android.
Java
1
star
40

type-ahead-search

Toy type-ahead search.
Java
1
star
41

nimbus

Nim
1
star
42

zk-select

Go
1
star
43

dotfiles

The most exciting thing you will ever see.
Vim Script
1
star
44

pipe-sem

C
1
star
45

webhook-test

webhook test
Python
1
star
46

frugal

Java
1
star
47

jump-consistent-hash

Go implementation of Jump Consistent Hash.
Go
1
star
48

config-parser

A simple API for parsing ini-like configuration files.
1
star