TheHingineer

  • Computer Networks


  • CN Part-1

  • CN Part-2

  • CN Part-3

  • CN Part-4

  • CN Part-5

  •  Congestion Control: Leaky Bucket, Token Bucket, and TCP Congestion Control

     Congestion kya hota hai? (What is Congestion?)

    • Flow Control sirf ek sender aur ek receiver ke beech ka mamla hai (receiver buffer overflow rokna). Lekin Congestion Control poore network aur intermediate routers ke traffic ko manage karne ka kaam karta hai.

    • Jab hazaron devices ek saath internet par data transmit karte hain aur total traffic router ki handling capacity ya link bandwidth se zyada ho jaata hai, toh routers ke buffers full ho jaate hain aur packets drop hone lagte hain. Isi situation ko Congestion (Traffic Jam) kehte hain.

    • Traffic ko shape aur police karne ke liye do famous open-loop algorithms use hote hain: Leaky Bucket aur Token Bucket. Aur closed-loop mein TCP ka AIMD congestion control use hota hai.

     1. Leaky Bucket Algorithm (Traffic Shaping)

    • Real-life analogy: Ek baalti (bucket) imagine kijiye jiske bottom mein ek chota hole (leak) hai. Chahe aap baalti mein kitna bhi tez paani daalein (bursty traffic), bottom se paani hamesha ek constant steady rate par hi tapkega. Lekin agar baalti bhar gayi toh extra paani overflow hokar beh jayega (packet drop).

    • Working: Host se aane wala irregular, bursty traffic router ke buffer (bucket) mein store hota hai aur outgoing link par strictly constant bit rate par transmit hota hai.

    • Drawback: Leaky bucket idle time ko utilize nahi karta aur bursty data ko bilkul allow nahi karta, chahe network link poora khali kyu na ho!

     2. Token Bucket Algorithm (Bursty Traffic Allowed)

    • Leaky Bucket ki kami ko door karne ke liye Token Bucket Algorithm banaya gaya.

    • Isme bucket mein data packets store nahi hote, balki Tokens store hote hain. Ek token generator constant rate r tokens/sec par bucket mein tokens daalta rehta hai (maximum capacity C tokens).

    • Working: Jab kisi packet ko transmit hona hota hai, toh use bucket se token nikalna padta hai. Agar bucket mein tokens available hain, toh packet turant transmit ho jaata hai. Agar tokens nahi hain, toh packet wait karta hai ya discard ho jaata hai.

    • Key Advantage: Agar system kuch der idle raha, toh bucket mein tokens accumulate ho jaate hain. Jab achanak bada burst data aata hai, toh wo saare accumulated tokens ek saath use karke high-speed burst traffic transmit kar sakta hai!

     Leaky Bucket vs Token Bucket Comparison

    Feature Leaky Bucket Algorithm Token Bucket Algorithm
    Bucket Contents Bucket mein actual Data Packets store hote hain. Bucket mein Tokens store hote hain.
    Output Rate Strictly Constant Output Rate (No bursts allowed). Average rate constant rehti hai, lekin Large Bursts allow hote hain.
    Packet Discarding Buffer full hone par incoming packets drop ho jaate hain. Bucket full hone par sirf extra tokens drop hote hain, data nahi.

     3. TCP Congestion Control (AIMD, Slow Start, Congestion Avoidance)

    TCP congestion control ke liye ek variable maintain karta hai jise Congestion Window (cwnd) kehte hain. Actual data transmission limit dono windows ka minimum hoti hai:

    Effective Window = min (cwnd, rwnd)

    TCP Congestion Control ke 4 interconnected phases hote hain:

    cwnd (MSS)
      ^
    16|                              /-- Timeout: cwnd drops to 1 MSS!
      |                             /
     8|             /--- Linear ---/ (Congestion Avoidance: cwnd = cwnd + 1)
      |            /
     4|       /---/ (Slow Start Threshold: ssthresh = 8)
     2|     /
     1|---/ (Slow Start: Exponential Growth: 1 -> 2 -> 4 -> 8)
      +--------------------------------------------------------> Time (RTT)

    1. Slow Start:
    Connection start hone par cwnd = 1 MSS hota hai. Har round trip time (RTT) mein har successful ACK par cwnd double hota hai: 1 -> 2 -> 4 -> 8 -> 16... (Exponential growth) jab tak ki wo Slow Start Threshold (ssthresh) tak na pahunch jaye.

    2. Congestion Avoidance (Additive Increase):
    Jab cwnd >= ssthresh ho jaata hai, toh TCP cautious ho jaata hai. Ab window exponentially nahi, balki linearly har RTT mein sirf 1 MSS badhti hai (cwnd = cwnd + 1).

    3. Congestion Detection (Multiplicative Decrease):
    – Case A: Timeout hone par (Severe Congestion): ssthresh = cwnd / 2, aur cwnd = 1 MSS ho jaata hai! Process fir se Slow Start se shuru hoti hai.
    – Case B: 3 Duplicate ACKs milne par (Mild Congestion): ssthresh = cwnd / 2, aur cwnd = ssthresh ho jaata hai (Fast Recovery), aur transmission direct Congestion Avoidance se resume hoti hai (without dropping to 1).

     Summary Table

    Mechanism Summary Punchline
    Leaky Bucket Traffic shaping that enforces constant output rate with zero burst tolerance.
    Token Bucket Accumulates tokens during idle periods, allowing bursty traffic without dropping packets.
    TCP AIMD Additive Increase (probe bandwidth cautiously), Multiplicative Decrease (cut window in half on loss).
    Scroll to Top