Testing a website using a slow connection

Aug 19, 2011
by Ivan

After seeing a weird behavior when loading one of our sites at work when my connection lagged, I tried to look for a way to slow down my browser's network to see how the site was slowly being loaded. After some work I ran into this blog post "Simulating slow or laggy network connections in OS X" but it wasn't the most friendly procedure.

After giving it a try I decided to create a short script and it works beautifully.

touch slow.sh
chmod 700

Then add this to the file

#!/bin/sh
export PATH=/bin:/usr/bin:/sbin:/usr/sbin

if [ $# -ne 1 ]; then
	echo "Error: pass 'start' or 'stop' "
	exit 0
fi

if [ $1 = "start" ]; then
	echo "- Slowing the tubes"

	sudo ipfw pipe 1 config bw 256Kbit/s delay 350ms
	sudo ipfw add 1 pipe 1 src-port 80
	sudo ipfw add 2 pipe 1 dst-port 80
	exit 0
fi

if [ $1 = "stop" ]; then
	echo "- Back to normal"

	sudo ipfw delete 1
	sudo ipfw delete 2
	sudo ipfw pipe 1 delete
	exit 0
fi

And that's it. Then you can slow down your internet by just typing:

./slow.sh start

And go back to normal with:

./slow.sh stop

 

Posted in