Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tellyworth/2ce28add99fe743c702c090c8144355e to your computer and use it in GitHub Desktop.
Save tellyworth/2ce28add99fe743c702c090c8144355e to your computer and use it in GitHub Desktop.
On OSX Yosemite and above, in a terminal window:
1. Switch to the root user.
$ sudo su -
2. Create a Dummynet pipe that represents a slow, unreliable network:
# dnctl pipe 1 config bw 10Kbit/s delay 300 plr 0.1 noerror
3. Add the pipe to the packet filter, and enable it. Change 'local.wordpress.dev' to the hostname or IP of your local test VM.
# echo "dummynet in proto {tcp,icmp} from local.wordpress.dev to any pipe 1" | pfctl -f -
# pfctl -e
4. Ping the VM to confirm that traffic shaping is working as expected.
# ping local.wordpress.dev
PING local.wordpress.dev (192.168.50.4): 56 data bytes
64 bytes from 192.168.50.4: icmp_seq=0 ttl=64 time=368.255 ms
64 bytes from 192.168.50.4: icmp_seq=1 ttl=64 time=368.513 ms
64 bytes from 192.168.50.4: icmp_seq=2 ttl=64 time=369.118 ms
64 bytes from 192.168.50.4: icmp_seq=3 ttl=64 time=368.516 ms
Request timeout for icmp_seq 4
64 bytes from 192.168.50.4: icmp_seq=5 ttl=64 time=368.274 ms
^C
--- local.wordpress.dev ping statistics ---
7 packets transmitted, 5 packets received, 28.6% packet loss
round-trip min/avg/max/stddev = 368.255/368.535/369.118/0.312 ms
5. To disable filtering and restore normal traffic to the VM:
# pfctl -f /etc/pf.conf
# dnctl -q flush
The rule given in step 3 affects traffic outbound from the VM to your browser. To apply it to inbound traffic, in order to test file uploads:
# echo "dummynet out proto {tcp,icmp} from any to local.wordpress.dev pipe 1" | pfctl -f -
To simulate dropped connections, instead of dropped packets, dnctl is not needed:
# echo "block return proto {tcp,icmp} from any to local.wordpress.dev probability 1%" | pfctl -f -
# pfctl -e
Note that the probability is per packet, not per request, so you'll want a much lower value than for packets. I recommend around 1%.
Disabling dropped connections is the same as step 5.
Some links to more details and other tools that do a similar job:
https://spin.atomicobject.com/2016/01/05/simulating-poor-network-connectivity-mac-osx/
http://www.thomashanning.com/network-link-conditioner/
https://www.npmjs.com/package/crapify
https://github.com/tylertreat/Comcast
http://toxiproxy.io/
https://jagt.github.io/clumsy/
And downloadable PDFs of the retro BASIC programming books I mentioned in my talk:
http://www.usborne.com/catalogue/feature-page/computer-and-coding-books.aspx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment