# Congestion Control

简单理解一下congestion control

* Congestion control&#x20;
  * Congestion: "too many sources sending too much data too fast for network to handle"&#x20;
  * Manifestations&#x20;
    * Long delays (queueing in router buffers)
    * Packet loss (buffer overflow at routers)&#x20;
* Different from flow control&#x20;
  * One sender too fast for one receiver&#x20;
* Causes / costs of congestion: scenario 1&#x20;
  * Simplest scenario&#x20;
    * One router, infinite buffers
    * Input, output link capacity: R&#x20;
    * Two flows&#x20;
    * No retransmissions needed&#x20;
    * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FaGofXKJqMz2N6ytZ1Tlf%2Fimage.png?alt=media\&token=f7653b06-444b-4eca-8bdf-33da92f89e26)
    * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FwWmQG8mZA0Fho4lgs8D9%2Fimage.png?alt=media\&token=8f89e0e9-5aa9-406d-8290-ae8587767e63)
    * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FfOnpcoOBKhrKBZv9dAeY%2Fimage.png?alt=media\&token=f283c5c6-1d3e-47f5-8219-ec29d4b0b304)
  * Another scenario
    * One router, finite buffer&#x20;
    * Sender retransmits lost, timed-out packet
      * Application-layer input&#x20;
      * Transport-layer input includes retransmissions&#x20;
      * Perfect knowledge: sender sends only when router buffers available&#x20;
      * Or some perfect knowledge&#x20;
        * Packets can be lost (dropped at router) due to full buffers&#x20;
        * Sender knows when packet has dropped: only resends if packet known to be lost&#x20;
        * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FCKn3TRv3Qkt4lVoO4I5X%2Fimage.png?alt=media\&token=e5c277d2-5ec7-4092-8098-445704992fbe)
    * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2Fjgx5EKhBAnI5D9lRsyTY%2Fimage.png?alt=media\&token=0d7ff7f0-b565-4d59-b4ab-2683b83fee46)
  * Relasitic scenario: un-needed duplicates&#x20;
    * Packets can be lost, dropped at router due to full buffers - requiring retransmissions&#x20;
    * But sender times can time out prematurely, sending two copies, both of which are delivered&#x20;
    * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FdS00W1adQBb8eFWlHTEZ%2Fimage.png?alt=media\&token=5c822852-b2ec-489f-98fd-8a6025dc34d1)
* Costs of congestion&#x20;
  * More work (retransmission) for given receiver throughput&#x20;
  * Unneeded retransmissions: link carries multiple copies of the packet&#x20;
    * Decreasing maximum achievable throughput&#x20;
  * When packet dropped, any upstream transmission capacity and buffering used for that packet was wasted!&#x20;
* Insights&#x20;
  * Throughput can never exceed capacity (link)
  * Delay increases as capacity approached&#x20;
  * Loss / retransmission decreases effective throughput&#x20;
  * Un-needed duplicates further decreases effective throughput&#x20;
  * Upstream transmission capacity / buffering wasted for packets lost downstream (congestion collapse)&#x20;
* Apporaches towards congestion control
  * End-to-end congestion control
    * No explicit feedback from network
    * Congestion inferred from observed loss, delay (i.e. timeout, ACKs)&#x20;
    * Approach taken by TCP&#x20;
  * Network-assisted congestion control
    * Router provide direct feedback to sending / receiving hosts with flows passing through congested router&#x20;
    * May indicate congestion level or explicitly set sending rates&#x20;
    * TCP ECN, ATM, DECbit protocols&#x20;

#### TCP Congestion control: AIMD

* approach: senders can increase sending rate until packet loss (congestion) occurs, then decreasing sending rate on loss event&#x20;
* ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FhYyz1BthhxxTgNqtkDIP%2Fimage.png?alt=media\&token=88e3262f-cb21-4188-a34f-e2158b56d270)
* **Additive increase: increase sending rate by 1 maximum segment size every RTT until loss detected**
* **Multiplicative decrease: cut sending rate in half at each loss event**&#x20;
  * Cut in half on loss detected by triple duplicate ACK (TCP Reno)&#x20;
  * Cut to 1 MSS (maximum segment size) when loss detected by timeout (tcp Tahoe)&#x20;
* AIMD: probing for bandwidth&#x20;
  * A distributed, async algorithm - has been shown to
    * Optimize congested flow rates network wide
    * Have desirable stability properties&#x20;
* Implementation&#x20;
  * Sender sequence number space&#x20;
  * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FQBeR2oWwpmsXmyPatYh3%2Fimage.png?alt=media\&token=05f81978-139d-448a-aac7-1b517e93d4c1)
  * TCP sender limits transmission: LastByteSent - LastByteAcked <= cwnd&#x20;
  * cwnd is dynamically adjusted in response to observed network congestion&#x20;
  * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FrBquDd7E8PPzwNQVNVaG%2Fimage.png?alt=media\&token=53fb84e0-b63c-4ce5-b777-7ca0b1b57812)
* TCP slow start
  * When connection begins, increase rate exponentially until first loss event&#x20;
  * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FknGqWgtqRU61bbrzdgDj%2Fimage.png?alt=media\&token=f31d7ccc-0ce1-49d8-bb92-c0f66bdf1323)
* **TCP from slow start to congestion avoidance**&#x20;
  * When should the exponential increase switch to linear?
    * When cwnd gets to 1/2 of its value before timeout
  * Implementation&#x20;
    * Variable ssthresh
    * On loss event, ssthresh is set to 1/2 of cwnd just before loss event&#x20;
    * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FzbSCGKuZ1XYLPhEsrsVi%2Fimage.png?alt=media\&token=0913dfa7-929c-493a-9fab-8705ae6d54b2)&#x20;

#### TCP CUBIC

* Is there a better way than AIMD to "probe" for usable bandwidth?
* Insight / intuition&#x20;
  * W\_max: sending rate at which congestion loss was detected
  * Congestion state of bottleneck link probably (?) hasn't changed much&#x20;
  * After cutting rate / window in half on loss, initially ramp to W\_max faster, but then approach W\_max more slowly&#x20;
  * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FDAmbRdu0T6TV9zqidaD9%2Fimage.png?alt=media\&token=3669995a-1658-4720-a1c4-2ea22962fba1)
* Operation
  * K: point in time when TCP window size will reach W\_max
    * K itself is tunable&#x20;
  * Increase W as a functino of the cube of the distance between current time and K
    * Larger increases when further away from K
    * Smaller increases when nearest K&#x20;
* Default in Linux, most popular for web services&#x20;

#### TCP and the congested "bottleneck link"

* TCP (classic, CUBIC) increase TCP's sending rate until packet loss occurs at some router's output: the bottleneck link&#x20;
* Understanding congestion: useful to focus on congested bottleneck link&#x20;
* Goal: keep the end-end pipe just full, but not fuller&#x20;
* Delay-based TCP congestion control&#x20;

  * Keeping sender-to-receiver pipe "just full enough"
  * RTT\_min - minimum observed RTT (uncongested path)&#x20;
  * Uncongested throughput with congestion window cwnd is cwnd / RTT\_min&#x20;
  * ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FLm6FyiFfup4C339nvCiq%2Fimage.png?alt=media\&token=150b87d5-5d24-453f-bbd9-18e428d04597)
  *

  ```
  <figure><img src="https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FDJzNAD67tTuJ7yztvAWd%2Fimage.png?alt=media&#x26;token=ec92b3f3-78b5-466e-9c02-06c651553070" alt=""><figcaption></figcaption></figure>
  ```

  * BBR deployed on Google's (internal) backbone network&#x20;
* Explicit congestion notification (ECN)
  * TCP deployments often implement network-assisted congestion control&#x20;
    * Two bits in IP header (ToS field) marked by network router to indicate congestion&#x20;
      * policy to determine marking chosen by network operator&#x20;
    * Congestion indication carried to destination
    * Destination sets ECE bits on ACK segment to notify sender of congestion&#x20;
    * &#x20;

      <figure><img src="https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FRKmJsEYOdbdigFMxpoWX%2Fimage.png?alt=media&#x26;token=382a9e52-752a-48bf-b6fe-c703ac259b6d" alt=""><figcaption></figcaption></figure>
    * both IP (IP header ECN bit marking) and TCP (TCP header, C,E bit marking)

### Fairness&#x20;

* Fairness goal: if K TCP sessions share the same bottleneck link of bandwidth R, each should have average rate of R / K&#x20;
* ![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FsWiQlQBnvc6siWPzGAqo%2Fimage.png?alt=media\&token=fb186b67-40e1-4307-9594-e2176aa38ca8)

#### Is TCP fair?&#x20;

* Example: two competing TCP sessions
  * Additive increase gives slope of 1, as throughput increases&#x20;
  * Multiplicative decrease decreases throughput proportionally&#x20;
*

```
<figure><img src="https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVORxAomcgtzVVUqmws%2Fuploads%2FDP4GHWxN6SdyeKw4LPdj%2Fimage.png?alt=media&#x26;token=4739e41a-025e-4ce2-b5c6-5cb33c4ae5b6" alt=""><figcaption></figcaption></figure>
```

* Fairness and UDP
  * Multimedia apps often do not use TCP&#x20;
    * Do not want rate throttled by congestion control
  * Instead use UDP
    * Send audio / video at constant rate, tolerate packet loss
  * There is no "Internet police" policing use of congestion control&#x20;
* Fairness, parallel TCP connections&#x20;
  * Application can open multiple parallel connections between two hosts
  * Web browsers do this, e.g., link of rate R with 9 existing connections
    * New app asks for 1 TCP, gets rate R / 10&#x20;
    * New app asks for 11 TCP, gets rate R / 2&#x20;
  * Is it fair??
