When testing distributed systems, sometimes it is necessary to find out the network tolerance before production deployment.
Network simulation in essence involves 3 parts
- Latency
- Bandwidth
- Packet loss
Setup
The following assumes you have two nodes set up
- server
- client
Latency
Before starting any tests, it is good to get a benchmark of your current setup.
From your client
node run
ping <server-ip-address>
Now let's add a 500ms latency
# tc qdisc add dev eth0 root netem delay 500ms
If you run ping
again, you will get a different result
Let's say we want to add some variance to the latency
Here we add a 10ms variance along a normal distribution in addition to the 500ms latency
Notice the use of change
instead of add
tc qdisc add dev eth0 root netem delay 500ms 10ms distribution normal
Packet loss
The following line adds a 10% packet loss in addition to a 250ms delay
tc qdisc change dev eth0 root netem loss 10% delay 250ms
Note: These changes do not persist across restarts
Bandwidth
Using Wondershaper
https://github.com/magnific0/wondershaper
For bandwidth control, you can use wondershaper
After installation you can run the following
wondershaper -a eth0 -u 30000 -d 10000
wondershaper -c -a eth0
Test bandwidth
Use iperf to test if bandwidth limitations are applied
On the server run iperf -s
to start the server
On the second node run iperf -c <server-ip-address>