2

I would like to test how loading external javascripts affect the page when remote servers are slow to respond.

I looked for tools that can slow down connection for specific sites but I could only find tools that slow down the whole network or that don't exist for Mac (like here or here)

Are there tools like that?

Community
  • 1
  • 1
mbdev
  • 6,343
  • 14
  • 46
  • 63

2 Answers2

1

Using the Detours App for Mac, you can redirect certain hosts to your own local web server. From your server, you can then fetch the resource (via curl, etc.), sleep for a certain amount of time, and then return the response.

Eli
  • 17,397
  • 4
  • 36
  • 49
0

Its not the easy way out, but you could use IPTABLES (unix ip-router) in conjunction with TC (traffic control)? This is quite extensive if you dont know how terminal bash-scripting works but you will need a terminal 100% for a proper solution.

If this does not work for you, try a simpler method: http://lartc.org/howto/lartc.ratelimit.single.html

Store this in for instance your home folder, call it bwm.sh

#!/bin/bash

# through this interface
IF=$1
# on this HOST
HOST=$2
# get the IP from HOST
HOSTIP="`nslookup $HOST|grep Address|grep -v "#"|cut -d " " -f2`"
# with this rate
your_rate=$3


# defaults /sbin/tc
TC="`whereis tc | sed 's/[^\ ]*.\([^\ ]*\).*/\1/'`" 
# defaults /sbin/iptables
IPTABLES="`whereis iptables | sed 's/[^\ ]*.\([^\ ]*\).*/\1/'`" 

#some number
PRIO="123"
# you create a new rule in the mangle table
IPT="$IPTABLES -t mangle"

echo "Program locations found: iptables: $IPTABLES and tc: $TC"
echo "down-rating bandwidth\n on $HOST\n to $your_rate whilst marking packages that origins\n from $HOSTIP\n with $PRIO on interface\n named $IF"
echo -n "starting setup.."

# apply custom filter
$IPT -N myfilter

# add it to the POSTROUTING chain
$IPT -A POSTROUTING -j myfilter

# if conntrack is used - restore a mark and allow the packets, which already have been marked, through - no need to check again

$IPT -A myfilter -p tcp -j CONNMARK --restore-mark
$IPT -A myfilter -m mark --mark $PRIO -j ACCEPT

# add to it your matching rule

$IPT -A myfilter -p tcp -s $HOSTIP -j MARK --set-mark $PRIO

# conntrack it optionally, so not every packet has to be rematched
$IPT -A myfilter -j CONNMARK --save-mark

# use that mark in a tc filter rule
echo qdisc add
$TC qdisc add dev $IF root handle 1: htb default 30
echo class add
$TC class add dev $IF parent 1: classid 1:1 htb rate $your_rate # <<<<<<<< fill in rate

echo sfq add
# add an SFQ qdisc to the end - to which you then attach the actual filter
$TC qdisc add dev $IF parent 1:1 sfq perturb 10
echo filter add
$TC filter add dev $IF parent 1:1 prio 1 handle $PRIO fw flowid 1:1
echo "done"

Now open terminal window and achieve root permissions

finder > terminal > open, we will go to user home and enter super user

cd; su

enter root password

start program with Interface, Hostname, Rate parameters

sh bwm.sh IF HOST RATE
mschr
  • 8,531
  • 3
  • 21
  • 35
  • Thanks for the answer! I feel bad to say that netem is not available for mac after all the effort. – mbdev May 02 '12 at 22:55
  • no sure what you mean by netem? but i guess that your point is the tools couldnt be found? – mschr May 03 '12 at 13:57
  • netem is the software that has the command line 'tc' that you use in your answer. You can find it here: http://www.linuxfoundation.org/collaborate/workgroups/networking/netem , and it's not available in a Mac – mbdev May 03 '12 at 17:27
  • ahh, didnt know that net emulator thing :=) however, for future lookups here, the correct package - in linux repositories anyways - is iproute(2), found a great wiki on subject here: http://wiki.robotz.com/index.php/Iproute2 – mschr May 03 '12 at 19:19
  • running a program like the one suggested (its actually a proxy server) is probably feasible enough, in developement environments anyways. But it would be quite the overkill to proxy web on your localhost on say, a laptop – mschr May 03 '12 at 19:22