Artifical Latency

While trying to reproduce an issue, it's often useful to be able to artificially introduce latency without simply killing a service. The tc command, coupled with iptables allows you to achieve that goal. Run all of the below as root.

All network traffic to/from a host

Add 10ms to all network activity:

tc qdisc add dev eth0 root netem delay 10ms

Show config:

tc -s qdisc

Undo it:

tc qdisc del dev eth0 root netem

Specific flows

Add 10ms to all HTTP responses from a webserver running on port 80 on this host:

tc qdisc add dev eth0 root handle 1: prio priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
tc qdisc add dev eth0 parent 1:2 handle 20: netem delay 10ms
tc filter add dev eth0 parent 1:0 protocol ip u32 match ip sport 80 0xffff flowid 1:2

Undo it:

tc qdisc del dev eth0 root handle 1: prio priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Comments

Popular posts from this blog

SSH Private Keys - RSA vs. OpenSSH

Google Wifi and Verizon FiOS