At work, access to the internet is provided by a 10 Mbit down / 1 Mbit up ADSL-connection. As we are a mid-size company, bandwidth is clearly a severe constraint. But it was not our biggest problem. Even simple web-browsing was very slow.

As I was setting up a monitoring environment based on Nagios and pnp4nagios, I started to graph the latency of our internet connection, just to prove that we have a problem.

Boy did we get that proof:

Just look at the y-axis, which scale is in milliseconds. For most of the day, the average latency is 175 ms, with some high spikes. Just browsing the web was a pain during times of high-latency, which was clearly almost all of the time.

I became so fed up with our slow internet access that I decided to take matters in my own hands and resolve the low latency issue. The solution? Traffic shaping.

I learned that as ADSL-connections are saturated, especially their upload capacity, you will experience high latency and packet loss. So the trick is to never saturate the connection.

I grabbed a Linux box with two network interfaces and placed it between our internet router and our firewall in bridge mode.

For actual traffic shaping I used wondershaper which is part of Debian or Ubuntu.

apt-get install wondershaper

The wondershaper script is extremely simple, it's specifically build to resolve the problem we face with our ADSL connection. It not only prioritises traffic, it allows you to limit bandwidth usage and thus prevent you from saturating the connection.

This simple example limits bandwidth a bit below full capacity, which dramatically improved latency.

Syntax:

wondershaper <interface> <rx> <tx>

Example:

wondershaper eth1 9500 700

As you can see, latency improved dramatically:

Again, look at the y-axis. We went from an average latency of 175 ms to an average of 35 ms. That's quite an improvement.

Can you spot on which day I implemented traffic shaping?

At the time of writing this blog post, the company is working on fiber internet access, resolving our internet woes, but it will take quite some time before that will be installed, so this is a nice intermediate solution.