knowplace.org

Introduction

Disclaimer:Certain things that will follow are false. Hopefully, they are gross simplifications that are useful in making some concepts easier to explain. Other things that will follow may be unintentionally false (if you notice anything, please let me know).

What is traffic / packet shaping?

Simply put, traffic shaping is an attempt to control network traffic in order to optimize or guarantee performance, low-latency, and/or bandwidth. Traffic shaping deals with concepts of classification, queue disciplines, enforcing policies, congestion management, quality of service (QoS), and fairness.

Why do you need a traffic shaper (or Chaos vs. Control)?

Despite (or maybe because of) the open and cooperative nature of the Internet, competition for available network resources tend to be unfair or selfish. Given that network bandwidth is a limited resource, traffic shaping lets you prioritize and manage network services.

Intelligently managed, traffic shaping improves your latency, service availability and bandwidth utilization without any drawback (theoretically). Imagine a typical business that needs to connect to their headquarters for a mission critical financial application, but application performance is too slow because of local users browsing the web or downloading *ahem* multimedia content. Imagine the other scenario where a typical home user is running a P2P application and his roomates complain because web browsing is now unacceptably slow due to the saturated uplink.

Traffic shaping can give you:

  • Granular control of network services
  • More efficient use of limited/shared resources
  • Guaranteed quality of service


What is a queue discipline?

A queue discipline is a strategy for managing a "queue." Imagine standing in line in the post office vs. waiting in the emergency room. Both have "items" in the queue that needs to be cleared in some manner, but have very different strategies.

Post offices typically use a first in first out strategy (classless FIFO). Customers are served in the order that they've arrived in the queue. On the other hand, this is an undesirable strategy for managing an emergency room (prioritized classful). Someone in a critical condition requires urgent attention regardless of their order of arrival. Suppose 10 people all show up at the same time, and there are only enough resources to deal with two people, what needs to happen? First you need to sort the queue (or line) into classes (e.g. critical, urgent, non-urgent, can-wait-indefinitely). Then you empty the queue based on priority of the different classes.

Note that these two queue disciplines (or qdisc) mentioned above are far from being comprehensive.

Linux and traffic shaping

Fortunately, Linux (since 2.2) has free (as in freedom and as in beer) tools for shaping network traffic. Especially since Linux kernel v2.4.20, (almost) everything is supported without a need to patch the kernel. Strictly speaking, the only tools required are in the (slightly patched) iproute2 package. Though some people also add in tcng to "simplify" the arcane tc configuration. If you want to use iptables (recommended) to classify the packets, then you may need to apply the classify patch from the iptables's patch-o-matic.

There are also a number of commercial solutions based on the Linux kernel, and some independent solutions. Note: Please don't ask me to recommend one. I don't have nearly enough experience with them to have an informed opinion.

 
Shane Tzen © 2008