Experiences in programming a traffic shaper

A traffic shaper regulates the transmission of packets according to a pre-determined rate, seemingly a straightforward program. A frequently used technique to achieve the prescribed rate is to interleave packet transmissions with sleeps, an operating system function. If the sleep duration cannot be accurately controlled, it can adversely impact the performance of the traffic shaper. We describe the problem caused by an inaccurate sleep, various algorithms for compensating for the inaccuracy, and how to accommodate intermittent data arrival streams at the same time. The objective is to produce an accurate, yet simple, robust, and efficient traffic shaper.