Leaky bucket shaping: choose an output rate and queue bound
Leaky-bucket shaping queues incoming traffic and releases it at a configured rate to smooth the output. A burst is delayed when the queue has room; when the queue is full, excess packets are dropped. Choose not only the output rate but also queue capacity and acceptable delay.
Leaky-bucket shaping queues incoming traffic and releases it at a configured rate to smooth the output. A burst is delayed when the queue has room; when the queue is full, excess packets are dropped. Choose not only the output rate but also queue capacity and acceptable delay.
The bucket that “leaks”
Think of packets as water entering a bucket, the output rate as the leak, and queue capacity as the bucket size. If arrivals exceed output, the queue grows; when arrivals stop, it drains. A simple constant-drain model turns variable input into a steadier output, though real implementations transmit packets discretely rather than continuously.
Suppose a link sends 1 MB/s and has room for 4 MB in an empty queue. A burst of 3 MB is sent over about 3 seconds; the last data waits about 2 seconds. A 5 MB burst exceeds the queue by 1 MB, which is dropped under this illustrative fixed-size model. Actual behavior depends on the implementation's overflow policy.
RFC 3290 describes leaky bucket primarily as shaping traffic leaving a network interface. Packet size, clock granularity, and competing traffic mean output only approximates a perfectly smooth rate.
Set rate, queue, and delay together
Set the output rate to what the link or next stage can sustain. A rate above the bottleneck can keep the queue growing or cause drops farther downstream.
Choose queue capacity from acceptable bursts and delay. A larger queue absorbs more traffic but can increase waiting time (bufferbloat).
Decide overflow behavior: drop new packets, drop lower-priority traffic first, or separate flows into queues. A FIFO queue can let one sustained flow delay others.
Specify the measurement point and unit. Bytes/s and packets/s produce different outcomes; use the unit that reflects the constrained resource.
As a simple estimate, queued volume Q divided by output rate R gives about Q/R seconds of wait when the queue was empty and no further congestion intervenes. At 1 MB/s, 4 MB ahead means roughly 4 seconds for the last data. Variable packet sizes and multiple queues change the actual delay.
Linux tc tbf is not literally a leaky bucket
Linux tc tbf is the Token Bucket Filter, not the leaky-bucket algorithm. It is still a useful shaping example: it queues packets and delays transmission according to a rate, with burst and either latency or limit bounds. Its manual warns that a burst that is too small can cause drops because tokens arriving per timer tick do not fit. Do not copy these values to another OS or service; verify its own algorithm, units, timer granularity, queue policy, and drop counters.
Measure output rate, queue depth, latency, and loss together. No interface was configured or tested for this article.
Sources
[RFC 3290, Appendix A.1](https://www.rfc-editor.org/rfc/rfc3290.html)
[Linux `tc-tbf(8)` manual](https://www.man7.org/linux/man-pages/man8/tbf.8.html)
[Linux `tc(8)` manual](https://man7.org/linux/man-pages/man8/tc.8.html)