BIT254 ยท 0 ยท 10 marks
Explain leaky-bucket algorithm. Illustrate with an example. What are its advantages and disadvantages?
Explain leaky-bucket algorithm. Illustrate with an example. What are its advantages and disadvantages?[10]
Quick answer
The Leaky Bucket Algorithm is a traffic shaping and congestion control mechanism used in computer networks to control the rate at which data packets are transmitted into the network. It smooths out bursty traffic and converts it into a steady, uniform stream of packets.
Leaky Bucket Algorithm
Definition and Concept
The name comes from the analogy of a bucket with a small hole at the bottom:
- Water (packets) poured into the bucket at any rate
- Water leaks out from the bottom at a constant, fixed rate
- If the bucket overflows, excess water (packets) is discarded
How It Works
The algorithm operates as follows:
- Incoming packets are placed into a FIFO queue (the bucket) of fixed capacity.
- Packets are transmitted (leak out) at a fixed rate, regardless of the input rate.
- If the bucket (queue) is full, any new incoming packets are discarded (dropped).
- If the bucket is empty, no packets are sent (output is idle).
Key Parameters:
| Parameter | Description |
|---|---|
| Bucket Size (B) | Maximum number of packets the queue can hold |
| Output Rate (r) | Fixed rate at which packets leave the bucket |
| Input Rate | Variable (bursty) rate at which packets arrive |
Algorithm Steps
1. Initialize bucket with capacity B and output rate r.
2. For each time slot:
a. Receive incoming packets.
b. If (current packets in bucket + new packets) <= B:
Add packets to bucket.
Else:
Discard excess packets (overflow).
c. If bucket is not empty:
Transmit r packets from the bucket.
Illustration with Example
Setup:
- Bucket size (B) = 10 packets
- Output rate (r) = 3 packets per time slot
Simulation Table:
| Time Slot | Packets Arriving | Packets in Bucket (Before Output) | Packets Sent | Packets Remaining | Packets Dropped |
|---|---|---|---|---|---|
| 1 | 5 | 0 + 5 = 5 | 3 | 2 | 0 |
| 2 | 8 | 2 + 8 = 10 | 3 | 7 | 0 |
| 3 | 6 | 7 + 6 = 13 > 10 | 3 | 7 | 3 |
| 4 | 0 | 7 + 0 = 7 | 3 | 4 | 0 |
| 5 | 2 | 4 + 2 = 6 | 3 | 3 | 0 |
| 6 | 0 | 3 + 0 = 3 | 3 | 0 | 0 |
Observations from the Example:
- At Time Slot 2, the bucket fills to exactly 10 (no drop).
- At Time Slot 3, 13 packets would be needed but bucket holds only 10, so 3 packets are dropped.
- Output is always a constant 3 packets/slot, regardless of input bursts.
- The bursty input is converted to a smooth, uniform output stream.
Diagram:
Bursty Input
||| |||| ||||||
| |
v v
+------------------+
| B U C K E T | <-- Fixed capacity (B)
| (FIFO Queue) |
+------------------+
|
| Fixed rate (r packets/slot)
v
Smooth Output
||| ||| ||| |||
Advantages of Leaky Bucket Algorithm
-
Traffic Smoothing: Converts bursty, irregular traffic into a smooth, constant-rate output stream, reducing network congestion.
-
Simplicity: The algorithm is simple to understand and easy to implement in hardware or software.
-
Congestion Control: Prevents network congestion by ensuring no host can send packets faster than the allowed output rate.
-
Predictable Output: The output rate is always fixed and predictable, making it easy for the network to plan bandwidth allocation.
-
Fairness: Ensures that no single host monopolizes network bandwidth by enforcing a strict rate limit.
Disadvantages of Leaky Bucket Algorithm
-
Packet Loss: When the bucket is full, incoming packets are simply dropped, which may be unacceptable for certain applications (e.g., real-time video, VoIP).
-
Inflexibility: The output rate is always fixed, even when the network is idle and has spare capacity. It cannot take advantage of available bandwidth.
-
Does Not Handle Bursts Well: Legitimate short bursts of traffic are not accommodated. Even if the network can handle a burst, the algorithm still enforces the fixed rate.
-
Delay: Packets may experience variable queuing delays inside the bucket before being transmitted.
-
No Differentiation: All packets are treated equally; there is no priority mechanism for urgent or important packets.
-
Wasteful During Low Traffic: If the input rate is lower than the output rate, the bucket remains partially empty and the full bandwidth is not utilized.
Comparison: Leaky Bucket vs Token Bucket
| Feature | Leaky Bucket | Token Bucket |
|---|---|---|
| Output rate | Always fixed | Variable (up to a maximum) |
| Burst handling | Not allowed | Allowed (up to token limit) |
| Packet drop | On overflow | On no token available |
| Flexibility | Less flexible | More flexible |
Summary
The leaky bucket algorithm is a fundamental traffic policing and shaping technique that enforces a constant output rate regardless of input burstiness. While it is simple and effective for smoothing traffic and preventing congestion, its rigidity in not accommodating bursts and its packet-dropping behavior are notable limitations. For applications requiring burst tolerance, the Token Bucket Algorithm is often preferred.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.