Transport Layer · Computer Networks

Leaky Bucket Algorithm

Watch lectures
SVGVector Architecture Diagram (SVG)
COMPUTER NETWORKS · Module 4★ High PriorityLeaky Bucket AlgorithmIT Sem 6 · Code 100602 · Traffic shapingMNEMONICLeaky bucket = bursty in, CONSTANT rate out; a full bucket overflows.Think of a bucket with a small hole at the bottom.Core BreakdownIdeaTraffic shaper: turns a bursty flow into a steady flow at a fixed rate R.The bucket is a buffer of size B; the hole lets data out at rate R.ArrivalPackets arrive at any rate and enter the bucket (queue) if there is room.If the bucket is full, the new packet is discarded (overflow).DeparturePackets leave at a constant rate R, whether the input is bursty or idle.Variable-size packets: send a fixed number of bytes per clock tick.Algorithm1. Packet arrives: if the queue has space, enqueue it; else drop it.2. Every tick: send up to R bytes from the front. 3. Repeat.EffectSmooths bursts, so downstream routers see predictable traffic.Cannot save idle time: a burst is never sent faster than R.UsesTraffic policing and shaping at network edges (e.g. ATM-style networks).Keeps flows within the rate agreed in the service contract.Diagram: Leaky BucketBurstyinputBucket Boverflow= droppedconstant rate ROutput rate R is FIXED (smoothing)Bucket full → packets discarded⚠️ Exam Traps & Viva Favorites① Output rate of leaky bucket?Always constant (rate R), even when the inputis bursty. Bursts are smoothed, not passed.A full bucket discards packets.② When are packets lost?When the bucket (buffer) is full: the input ratestays above R long enough to fill it.Bigger bucket = fewer drops, more delay.③ Leaky vs token bucket?Leaky: rigid fixed output, no bursts. Token:saves tokens when idle, so a burst up to bcan leave at full speed.Tip: leaky smooths · token burstsMaster Revision Table(learn it row by row!)ParameterSymbolMeaningEffectBucket sizeBBuffer capacityLarger B: fewer drops, more delayLeak rateRConstant output rateSets the average rateInputvariableBursty arrivalsSmoothed by the bucketOverflowdropArrival when bucket is fullPacket is discardedIdle timenoneOutput stays at R or emptyNo credit is savedPacket sizebytes / tickFixed bytes per clock tickHandles variable packetsQUICK FACTSOutput rate R is constant · it never sends faster than R, even after idle timeExample: R = 2 Mbps, burst 10 Mbps for 1 s → bucket must hold 8 Mb or drop the restRelated: token bucket allows bursts · both are traffic shaping techniquesVERIFIED★ Golden rule: leaky bucket = fixed outputrate; bursts are queued or dropped.

The Leaky Bucket Algorithm


1. Concept of Traffic Shaping

In computer networks, computer data traffic is naturally bursty: an application may transmit zero packets for seconds, then suddenly dump thousands of packets in a millisecond burst (e.g., loading a heavy webpage).

If bursty traffic enters a network unthrottled, intermediate router buffers overflow, resulting in severe packet loss and congestion. Traffic Shaping smooths out bursty incoming packet streams into a predictable, steady output rate.


2. The Leaky Bucket Mechanism

The Leaky Bucket Algorithm uses the physical analogy of a bucket with a small hole in the bottom:

MermaidDiagram
Rendering diagram…

Operational Rules:

  1. The Bucket (Buffer): An in-memory FIFO queue of finite capacity CC bytes (or packets).
  2. The Leak (Output Rate): Packets leave the buffer and enter the network at a strictly constant rate RR, regardless of how fast or bursty packets arrive.
  3. Overflow / Packet Dropping:
    • If packets arrive faster than they leak out, water rises in the bucket.
    • If a burst of packets arrives when the bucket is already full, the excess packets spill over and are discarded (or marked as low-priority discard candidates).

3. Mathematical Model and Solved Numerical

Problem Statement:

A computer transmits data into a network regulated by a Leaky Bucket algorithm.

  • Maximum output rate: R=2 MB/secR = 2\text{ MB/sec}.
  • Bucket capacity: C=10 MBC = 10\text{ MB}.
  • The host suddenly sends a burst of data at 10 MB/sec10\text{ MB/sec} for 1.5 seconds1.5\text{ seconds}.
  1. How much data is generated by the host?
  2. How much data leaks out during this 1.5 seconds1.5\text{ seconds}?
  3. How much data accumulates in the bucket?
  4. Is there any packet loss?
  5. How long will it take for the bucket to completely empty after the burst ends?

Step-by-Step Solution:

  1. Total Data Generated:
Data=10 MB/s×1.5 s=15 MB\text{Data} = 10\text{ MB/s} \times 1.5\text{ s} = \mathbf{15\text{ MB}}
  1. Data Leaked Out during Burst:
Leaked=R×t=2 MB/s×1.5 s=3 MB\text{Leaked} = R \times t = 2\text{ MB/s} \times 1.5\text{ s} = \mathbf{3\text{ MB}}
  1. Data Remaining in Bucket:
Accumulation=Input−Leaked=15 MB−3 MB=12 MB\text{Accumulation} = \text{Input} - \text{Leaked} = 15\text{ MB} - 3\text{ MB} = 12\text{ MB}
  1. Packet Loss Evaluation:
    • The bucket capacity is C=10 MBC = 10\text{ MB}.
    • Since 12 MB>10 MB12\text{ MB} > 10\text{ MB}, the bucket overflows:
Packet Loss=12 MB−10 MB=2 MB discarded!\text{Packet Loss} = 12\text{ MB} - 10\text{ MB} = \mathbf{2\text{ MB discarded!}}
  • The bucket holds its maximum capacity: 10 MB10\text{ MB}.
  1. Time to Completely Empty the Bucket:
tempty=Data in BucketLeak Rate=10 MB2 MB/s=5 secondst_{\text{empty}} = \frac{\text{Data in Bucket}}{\text{Leak Rate}} = \frac{10\text{ MB}}{2\text{ MB/s}} = \mathbf{5\text{ seconds}}

4. Strengths and Inefficiencies of Leaky Bucket

Major Strength:

  • Absolute Rate Guarantee: Guarantees that transmission into the network never exceeds the configured rate RR, completely eliminating burst-induced congestion.

Fundamental Limitation:

  • Inflexible to Idle Periods:
    • The Leaky Bucket cannot send bursts even when the network is completely idle and capacity is available!
    • If the host was silent for an hour and then wants to send a legitimate 5 MB burst, the Leaky Bucket forces it to drip out at 2 MB/s, introducing artificial transmission delay.
    • This inflexibility led directly to the development of the Token Bucket Algorithm.

Frequently Asked Questions

QWhat is the primary function of the Leaky Bucket algorithm?

To reshape bursty, irregular packet arrivals into a smooth, constant-rate output data stream.

QWhat happens when the input burst size exceeds the bucket capacity?

The excess packets overflow the FIFO buffer and are dropped, resulting in packet loss.

QWhy is the Leaky Bucket algorithm restrictive for bursty data transfers?

It enforces a rigid output rate regardless of whether the network has surplus unused capacity, preventing hosts from taking advantage of available idle bandwidth for quick bursts.

QWhat is traffic shaping?

Traffic shaping smooths bursty traffic into a steady, predictable output rate before it enters the network, reducing router buffer overflow and congestion.

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Computer Networks modules