The Leaky Bucket Algorithm is a method used in networking to regulate the rate at which data is transmitted. It maintains a steady sending speed, even when data arrives in sudden bursts, preventing the network from becoming overloaded.
Incoming packets are stored in a fixed-size buffer before transmission.
Data is released into the network at a constant rate.
Packets arriving after the buffer is full are discarded.
Helps routers and switches use bandwidth in a controlled manner.
A Leaky Bucket algorithm uses a FIFO queue to regulate traffic. For fixed-size packets, a constant number are removed at each clock tick. For variable-size packets, transmission is based on a fixed byte/bit rate. The following is an algorithm for variable-length packets:
1. Initialize a counter to n at the tick of the clock. 2. Repeat until n is smaller than the packet size of the packet at the head of the queue.
Since, n < size of the packet at the head of the Queue, i.e. n < 450Therefore, the procedure is stopped.
Initialize n = 1000 on another tick of the clock.
This procedure is repeated until all the packets are sent into the network.
Below is the implementation of above explained approach:
Output
Buffer size= 4 out of bucket size= 10 Buffer size= 7 out of bucket size= 10 Buffer size= 10 out of bucket size= 10 Packet loss = 4 Buffer size= 9 out of bucket size= 10
Leaky Bucket vs Token Bucket
Leaky Bucket
Token Bucket
When the host has to send a packet , packet is thrown in bucket.
In this, the bucket holds tokens generated at regular intervals of time.
Bucket leaks at constant rate
Bucket has maximum capacity.
Bursty traffic is converted into uniform traffic by leaky bucket.
If there is a ready packet , a token is removed from Bucket and packet is send.
In practice bucket is a finite queue outputs at finite rate
If there is no token in the bucket, then the packet cannot be sent.
Advantage
Prevents sudden traffic spikes that can cause congestion.
Produces a smooth and consistent data flow.
Simple to implement and requires minimal control logic.
Makes bandwidth usage more predictable.
Suitable for applications that require steady transmission.
Disadvantages
Does not handle burst traffic efficiently.
Packets may be dropped when the buffer becomes full.
Available bandwidth may remain unused during low traffic periods.
Less adaptable to dynamic network conditions.
Not ideal for highly variable data traffic.
Applications
Traffic shaping in routers and switches.
Bandwidth control in Quality of Service (QoS) networks.
Voice over IP (VoIP) to ensure stable call quality.
Video streaming for continuous data delivery.
Legacy networks such as ATM that require predictable traffic patterns.