- Asked 4/11
- 2074 Chaitra · 4 marks
- 2073 Chaitra
- 2072 Chaitra · 4 marks
- 2069 Chaitra · 3 marks
Token bucket algorithm
Short answer
Token bucket limits average rate r, allows bursts of up to b packets. Tokens added at rate r into bucket of capacity b; a packet consumes one token if available, else waits or is dropped. Idle hosts accumulate tokens for bursts. Unlike leaky bucket, it permits variable output rates and saves idle credit as tokens.
Explain the token bucket algorithm for congestion control, with a diagram.
The token bucket algorithm is a traffic-shaping / congestion-control method that limits the average rate of a flow but still allows short bursts.
Working
- A bucket of capacity b tokens holds tokens. Tokens are added at a constant rate r (tokens per second). If the bucket is full, new tokens are discarded.
- One token permits one packet (or one byte, in byte-based versions) to be sent.
- When a packet arrives, if enough tokens are present, the tokens are removed and the packet is sent at once. If not, the packet waits (shaping) or is dropped/marked (policing).
- An idle host saves tokens, so later it can send a burst of up to b packets.
tokens added at rate r
|
v
+--------+
| bucket | capacity b
| o o o |
+---+----+
| one token per packet
packets v
-------> [ queue ] ---(token available?)---> network
Example
Bucket capacity b = 5 tokens, r = 1 token per tick, 1 token per packet, bucket initially full.
| Tick | Packets arrive | Tokens available | Sent | Waiting |
|---|---|---|---|---|
| 0 | 5 | 5 | 5 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 2 | 0 | 2 | 0 | 0 |
| 3 | 3 | 3 | 3 | 0 |
| 4 | 3 | 1 | 1 | 2 |
| 5 | 0 | 1 | 1 | 1 |
| 6 | 0 | 1 | 1 | 0 |
The burst of 5 packets passes at once, but in the long run the rate cannot exceed 1 packet per tick.
Token bucket vs leaky bucket
| Point | Leaky bucket | Token bucket |
|---|---|---|
| Output rate | Constant | Variable; bursts allowed |
| Idle credit | Not saved | Saved as tokens |
| Bursts | Smoothed out | Allowed up to b |
| When bucket is full | Packets discarded | Tokens discarded, packets kept |
If M is the peak output rate of the link, the maximum time S for which a burst can be sent at rate M is S = b / (M − r).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Token ring mutual exclusion · Distributed System, chapter 6 · asked 3×
- Mutex requirements; token vs non-token · Distributed System, chapter 6
- PID control operation with block diagram · Embedded System, chapter 7 · asked 4×
- Closed loop control system block diagram explained · Control Systems, chapter 1 · asked 4×