Simulating High Latency Networks with Linux and Netem

Recently I wanted to simulate “slow” requests against a web server in order to investigate how high latency requests impacted the system overall. After some initial experimentation with writing my own code (in python), I started looking around for other solutions. I wanted to be able to use Multi-Mechanize, one of my favorite tools for http testing, without heavy modification. Eventually I stumbled onto netem.  From the FAQ:

Netem allows testing of protocols and applications on a local network with simulated wide area networks. This was originally done to test congestion algorithms in TCP/IP, but is equally applicable to web applications and file servers.

It’s dirt simple to use, and allows you to stick with whatever http traffic generating tools you like.  Here’s a few simple examples along with their impact.

Multi-Mechanize Configuration

run_time: 30
rampup: 0
results_ts_interval: 5
progress_bar: on
console_logging: off
xml_report: off
threads: 3

Multi-Mechanize Test Script

import httplib
import time

class Transaction(object):
    def __init__(self):
        self.custom_timers = {}

    def run(self):
        start_timer = time.time()
        conn = httplib.HTTPConnection('')
        conn.request('GET', '/')
        resp = conn.getresponse()
        content =
        latency = time.time() - start_timer</p>
        self.custom_timers['Google'] = latency
        assert (resp.status == 200), 'Bad HTTP Response'

if __name__ == '__main__':
    trans = Transaction()
    print trans.custom_timers

First, the control run (no artificial latency introduced):

Next, let’s add 100ms latency:

[root@aenea multi-mechanize_1.011]# tc qdisc change dev wlan0 root netem delay 100ms

Now let’s do 100ms latency, with a 20ms variation with a normal distribution:

[root@aenea multi-mechanize_1.0.11]# tc qdisc change dev wlan0 root netem delay 100ms 20ms distribution normal

This is really just scratching the surface with netem.  You can use it for:

  • Delay
  • Variable Delay
  • Delay Distribution
  • Packet Loss
  • Packet Reordering
  • Rate Control

Have fun!

About taotetek

Sometimes stereotypical but never ironic. You can't stop the signal, Mal. All my opinions are my own, unless I stole them from you.
This entry was posted in linux kernel, networks, Python, testing and tagged , , , . Bookmark the permalink.

2 Responses to Simulating High Latency Networks with Linux and Netem

  1. jeffm says:

    thank you, very nice post. how did you make the nice graphs?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s