CComputer Science, Built

Act VII · Many Machines

Part 37 of 61

Networks II: Reliable Conversation

Degreestarts at this level52 min of film18 chaptersprerequisites: Part 22, Part 30, Part 36

How do you build a reliable conversation, shared fairly, on a network that loses packets?

The part opens with the Job's novels, 24,971,555 bytes, sent from Frankfurt to San Francisco over a link that loses one packet in 1,000: Reno takes 34.9 s, CUBIC 24.2 s, BBR 3.2 s. It builds reliability from nothing: stop-and-wait, the alternating bit, Go-Back-N and Selective Repeat, with the theorem on how many sequence numbers a window needs tested at its edge. TCP adds the handshake, SYN cookies, flow control and a timer that learns the round trip. Then the part turns to October 1986, when the link from the Lawrence Berkeley Laboratory to UC Berkeley fell from 32 kb/s to 40 b/s, reproduces the collapse with fixed windows, and applies Jacobson's cure. Chiu and Jain's phase plane shows why the cure is additive increase with multiplicative decrease, one tooth of the sawtooth gives the Mathis formula, and Kelly's theorem reads the whole of it as dual ascent on link prices. Queues, bufferbloat, CoDel, CUBIC and BBR follow, then DNS, HTTP/2 against QUIC, and caches under Zipf's law. It ends with the novels fetched over the series' own TCP, ledger row 14, and with the 2022 starvation theorem: low delay, a full link and fairness under jitter cannot all be had.

What you need. Geometric series, expectations, and Lagrange multipliers for the chapter on optimization.

Mathematics, ideas and history
sliding windows, TCP, the 1986 collapse, AIMD and Chiu–Jain, the Mathis formula, bufferbloat, BBR, NUM, DNS, HTTP/3 and QUIC
What we build or compute
our TCP; the Job fetched over a lossy link

What you will be able to do

Degree

  • Trace stop-and-wait, Go-Back-N and Selective Repeat through a loss, and compute their utilization.
  • Explain the three-way handshake, flow control and the congestion window, and why the 1986 collapse happened.
  • Retell Chiu and Jain's four-line proof that AIMD converges to equal shares.

Graduate

  • Prove that Go-Back-N needs a window below the sequence space and Selective Repeat at most half of it.
  • Derive the Mathis formula from one tooth of the sawtooth, and the retransmission timer from SRTT and RTTVAR.
  • Solve a small network utility maximization by dual ascent and read the prices.

Research

  • State the starvation theorem for delay-convergent congestion control and explain the role of non-congestive delay.
  • Measure the delay a rule must accept to stay fair under ACK jitter, and say which part of that trade-off is open.

Industry

  • Size socket buffers to a bandwidth-delay product, and choose between CUBIC and BBR on a lossy long path.
  • Diagnose bufferbloat and cure it with CoDel, and choose DNS TTLs and cache sizes on purpose.

Contents

Each chapter has a home level. Choose a track to see what to read and watch: Degree 27 min · Graduate 51 min · Research 52 min · Industry 39 min.

  1. 0Thirty novels from FrankfurtDegree2 min
  2. 1The transport problemDegree2 min
  3. 2Reliability from scratchDegree4 min
  4. 3Sliding windowsDegree3 min
  5. 4TCPDegree3 min
  6. 5Timers that learnGraduate2 min
  7. 6Congestion collapseDegree4 min
  8. 7AIMDDegree3 min
  9. 8The Mathis formulaGraduate3 min
  10. 9QueuesIndustry3 min
  11. 10Modern congestion controlIndustry4 min
  12. 11TCP as optimizationGraduate4 min
  13. 12NamesDegree2 min
  14. 13The web's transportIndustry3 min
  15. 14Caches at the edgeIndustry2 min
  16. 15The novels, over our TCPGraduate3 min
  17. 16Frontier: can congestion control be fair?Research1 min
  18. Recap, problems, and where this comes backAll tracks3 min

Also on this page: Lecture · Key results · Try it · Lab · Problems · Notes and sources · 中文 · Build the film.

Lecture

The text of each chapter is the film's narration, as it is spoken, so you can read along or revise without the film. The pictures are in the film.

Thirty novels from FrankfurtDegree2 min

The thirty novels we have been counting all series live, this time, on a server in Frankfurt. Pebble 1, in San Francisco, fetches them: twenty-five megabytes, seventeen thousand packets, across a path with a round trip of a hundred and eight milliseconds and a hundred megabits a second to spare. The path is not perfect. One packet in a thousand is lost on the way, and IP, as we saw last time, does nothing about it. Our TCP fetches them three times, with three different rules for how fast to send. Reno, the rule of 1990, takes thirty-five seconds. CUBIC, the default on Linux, twenty-four. BBR, Google's rule of 2016, three. The physics allows two point two: the bytes at a hundred megabits a second, plus the round trips to ask. Same bytes, same link, same losses. Why is one rule eleven times slower than another? And how does anything arrive complete and in order at all, over a network that loses, reorders and duplicates packets?

Here is what each did. The height is each sender's window, the most packets it allows in flight, sent but not yet acknowledged, on a logarithmic scale. To keep a hundred megabits a second busy across a hundred and eight milliseconds, about nine hundred packets must be in flight at once: the pipe. Reno climbs toward it, one packet per round trip, and halves its window at every loss. With one loss in a thousand packets it never gets close. CUBIC climbs faster, along a cubic curve. BBR ignores the losses altogether. It measures the pipe, fills it, and stays there. Each of these is a theory of what a lost packet means, and this part builds all of them.

1The transport problemDegree2 min

Send ten thousand numbered datagrams across a channel like the Internet: one percent loss, an occasional duplicate, and a few packets held back in a queue while later ones overtake them. These are the first twenty to arrive. Twelve has been overtaken by seven others. Of ten thousand, a hundred and nine never arrive, eighteen arrive twice, and two hundred and eighty-four arrive after a packet sent later. This is all IP promises: best effort. Queues overflow and drop; a corrupted frame fails its CRC and is thrown away; routes change in the middle of a transfer; a radio resends a frame whose acknowledgement it missed. A program reading a file, or a web page, wants something else entirely: a stream of bytes, every one of them, exactly once, in order. Building that on top of this is the transport layer's job.

TCP, the transmission control protocol, makes the other contract. Every byte arrives, or the program is told the connection failed. Bytes come out in the order they went in, each exactly once. There are no messages, only a stream. It costs a handshake before any data flows, twenty bytes of header on every packet, and a sender that sometimes waits when it could send. And notice who keeps these promises: only the two computers at the ends. The routers in between know nothing about the conversation, exactly as the end-to-end argument of the last part said they should not. Everything in the next three chapters happens inside two machines, talking through a network that will not help.

2Reliability from scratchDegree4 min

The simplest protocol that could possibly work. The sender sends one packet and starts a timer. The receiver, on getting a packet, sends back an acknowledgement, an ACK. When the ACK arrives, the sender sends the next packet. If a packet is lost, no ACK comes. The timer expires, and the sender sends the same packet again. Corruption needs no separate treatment: a checksum detects it, and a corrupted packet is thrown away, so it becomes a loss. Loss is the only failure left. Retransmission handles it, as long as the channel delivers something eventually.

ACKs can be lost too. Here the packet arrives, but its ACK does not. The sender's timer expires, and it sends the packet again. To the receiver, this looks exactly like the next packet. Without more information it delivers the same data twice. The fix is to number the packets. With stop-and-wait, the receiver is only ever unsure between the packet it just got and the next one, so a single bit is enough: packets are numbered zero, one, zero, one. This is the alternating-bit protocol, published in 1969 by Bartlett, Scantlebury and Wilkinson at Britain's National Physical Laboratory. The receiver acknowledges the bit it received, and passes a packet up only if its bit is the one expected next. We tested it: twenty runs of five hundred packets, losing one packet or ACK in ten. Every run delivered exactly zero to four hundred ninety-nine, once each, in order.

That proof of correctness assumed something the Internet does not give: that packets arrive in the order they were sent. Suppose an old copy of a packet with bit zero is delayed in some queue. Meanwhile the conversation moves on, and the receiver comes to expect bit zero again. The old copy arrives, carries the right bit, and is delivered as new data. We repeated the test with one packet in five delayed. Not one run of twenty was correct; the first went wrong at position eight, delivering packet six a second time. One bit is enough on a wire, never on a network of queues. The cure is many sequence numbers, enough that a number is reused only after any old packet carrying it must be dead. TCP numbers bytes with thirty-two bits, and IP's time-to-live bounds how long a packet can wander.

Stop-and-wait is correct, and hopeless. Call the packet length L and the link rate R. Sending takes L over R; then the sender sits idle for a whole round trip, waiting. The fraction of time the link is busy is L over R, divided by the round trip plus L over R. Our simulator agrees with the formula to four digits, at every link speed: one tenth, one hundredth, one thousandth. The faster the link, the worse it gets. Across the Atlantic at a gigabit a second, a packet takes twelve microseconds to send and a hundred and eight milliseconds to acknowledge. Stop-and-wait uses a hundredth of a percent of the link: a tenth of a megabit, out of a thousand. The only way out is not to wait: keep many packets in flight at once.

3Sliding windowsDegree3 min

Instead of one packet at a time, allow W packets to be sent and not yet acknowledged: a window over the stream. The sender sends the first six and waits. As ACKs come back for zero, one and two, the window slides forward, and six, seven and eight go out. A steady stream of ACKs clocks out a steady stream of packets. In a round trip the sender now transmits W packets instead of one, so the utilization is W times larger, until it reaches one. To fill the pipe, the window must cover a whole round trip of sending: the bandwidth-delay product of the last part. Across the Atlantic at a gigabit a second, that is nine thousand packets in flight.

With many packets in flight, what happens when one is lost? There are two classic answers. Go-Back-N keeps the receiver simple. It accepts only the next packet in order and discards anything after a gap, acknowledging, again and again, everything up to the last good packet. When the sender's timer expires, it goes back and resends the lost packet and every packet after it. Selective Repeat makes the receiver work harder. It buffers packets that arrive after a gap, and acknowledges each one individually. The sender resends only the packet that was lost, and when it arrives, the receiver delivers the whole run at once. TCP began close to Go-Back-N and has moved, with selective acknowledgements, to Selective Repeat.

With a window, how many sequence numbers are enough? With numbers taken modulo S, Go-Back-N is correct exactly when the window is at most S minus one, and Selective Repeat exactly when it is at most half of S. Here is why half. Suppose the receiver has just accepted packets zero to W minus one, and moved its window on to W through two W minus one, but every one of its ACKs was lost. The sender, hearing nothing, resends packet zero. If two W is more than S, the number zero is the same as S, which is inside the receiver's new window, and the receiver accepts an old packet as new data. If two W is at most S, what the sender might send and what the receiver might expect never share a number, so nothing is misclassified. Go-Back-N's receiver expects only one packet, which gives W plus one at most S. We tested the edges with three-bit numbers, S equal to eight, ten runs each. Go-Back-N with seven: always correct; with eight: never. Selective Repeat with four: always; with five: never. The bound is exact.

4TCPDegree3 min

TCP is those ideas, engineered. Its header is twenty bytes. The ports, as in UDP. Then a thirty-two-bit sequence number, which counts bytes, not packets: the position in the stream of this segment's first byte. The acknowledgement number is cumulative: it names the next byte the receiver expects, which says everything before it has arrived. An option, selective acknowledgement, adds the blocks received beyond a gap, which gives the sender Selective Repeat's information. Flags open, acknowledge, close and reset connections, and the window field says how much more the receiver can buffer. A connection carries data both ways at once, so every segment can carry data in one direction and an acknowledgement for the other.

Before any data, the two ends must agree on where each stream starts. The client sends a segment with the SYN flag and its initial sequence number, x. The server replies with its own SYN, its own number y, and an acknowledgement of x plus one. The client acknowledges y plus one, and can send its request in the same segment. Each initial number is chosen at random, so that a delayed segment from an earlier connection between the same ports, or one forged by someone who cannot see the traffic, is unlikely to fall inside the window. The cost is time. The response's first byte arrives two round trips after the SYN was sent: two hundred and sixteen milliseconds to Frankfurt, before any encryption is set up. The last chapter of this part is about removing those round trips.

One more thing a sender must respect: the receiver. If the program reading the data is slow, its buffer fills. So every ACK carries the window: how many more bytes the receiver has room for. The sender never has more than that in flight. This is flow control, protecting the receiver. It also caps the speed: at most one window per round trip, whatever the link. The original header gave the window sixteen bits, sixty-four kilobytes, which allows under five megabits a second to Frankfurt. In 1992 an option let both ends scale the window by up to two to the fourteen. A fast transfer across an ocean needs a buffer as large as the bandwidth-delay product: one point three five megabytes at a hundred megabits a second. Protecting the network, rather than the receiver, is the much harder problem, and it is the next three chapters.

5Timers that learnGraduate2 min

A sender that retransmits must decide how long to wait. Too short, and it resends packets that were only delayed, adding traffic to a network that is already slow. Too long, and every loss costs a long silence. The right wait depends on the round trip, and the round trip is not a constant. Here is one flow from San Francisco to Frankfurt, sharing a bottleneck with five others that join over time. Its round trips start at the hundred and eight milliseconds of light in fibre and climb, as queues build, past three hundred. The timer must learn this, from samples, as it goes.

The original TCP specification kept a smoothed average of the samples, and waited a fixed multiple, beta, of it, with beta between one point three and two. Van Jacobson and Mike Karels, in 1988, also kept a smoothed average of how far each sample strays from the mean, and waited the mean plus four of those deviations. Here are the two timers over our samples. The fixed multiple of two stays far above the samples, all the time. Jacobson's hugs them when they are steady and opens up when they swing. Count the samples that arrived after the timer would have fired, each a needless retransmission. With beta one point three, fifteen. With beta two, none, but it waits almost half a second on average before recovering a real loss. Jacobson's timer fires early once, and waits a third less. Measuring the variance is what makes a timer both safe and quick, and the same estimator still runs in every TCP today.

6Congestion collapseDegree4 min

In October 1986, the link between the Lawrence Berkeley Laboratory and the University of California at Berkeley, four hundred yards and three routers apart, normally carried thirty-two kilobits a second. Then, for days, it carried forty bits a second. A thousandfold drop, and the links were not idle: they were completely busy. Every TCP of the time sent a full window as fast as the receiver allowed, with no thought for the network in between. Queues in the routers overflowed and dropped packets. Retransmission timers, which did not account for time spent waiting in queues, fired for packets that were only delayed. And the links filled with copies of packets that had not been lost, each one making the queues longer and the next timeouts more likely. John Nagle had predicted this, and named it, two years earlier: congestion collapse.

We can make it happen. Four flows share a two-megabit link, with hundred-millisecond round trips and a queue of thirty packets. Each runs a TCP of 1986: a fixed window, a fixed timer of two hundred milliseconds, and on a timeout, resend everything outstanding. We raise the window and measure the goodput, the rate of new data delivered. While the total window is small, goodput rises with it. Then the windows outgrow the pipe by so much that packets wait in the queue longer than the timer allows: the timers fire, and copies of waiting packets join the queue behind them. Goodput falls off a cliff, to a little over one megabit, while the link stays almost perfectly busy, carrying eleven thousand retransmissions a minute, most of them packets that were never lost. Our collapse is fifty percent, not a thousandfold, because we have one hop, not three, and a gentler timer. Now replace each sender with Jacobson's TCP. Goodput is one point nine four megabits at every load: the link's capacity, minus headers.

Van Jacobson, at the Berkeley lab, and Mike Karels diagnosed the collapse and published the cure in 1988. The idea is conservation. A connection in equilibrium should put a new packet into the network only when an old one leaves it. An ACK is the evidence that a packet has left, so each ACK releases one new packet. The ACKs return at the rate the bottleneck delivers, so the sender's pace automatically becomes the bottleneck's. Conservation fails if packets are resent while still in the network: hence the timer of the last chapter. And the right amount in flight must be found. A new variable, the congestion window, limits it. In a network of reliable links, a lost packet almost always means some queue overflowed, so a loss halves the window, and each round trip without loss adds one packet. Finally, slow start, to reach equilibrium in the first place.

Here is our Reno, alone on a ten-megabit link with a hundred-millisecond round trip, and a buffer as large as the pipe. Slow start is not slow: every ACK adds one packet to the window, so the window doubles each round trip, one, two, four, eight, until a queue overflows. From then on, congestion avoidance. Each ACK adds one over the window, so the window grows by one packet per round trip, a straight line, until the buffer overflows again and the window halves. And Reno does not wait for a timer: when three later packets have been acknowledged and one has not, that one is presumed lost, and is resent at once. This is the sawtooth, the heartbeat of the Internet since 1990. With a buffer of one pipe, the halving never empties the link: utilization is ninety-nine percent.

7AIMDDegree3 min

Additive increase, multiplicative decrease. Why should a TCP add one packet per round trip but halve its window on a loss? In 1989 Dah-Ming Chiu and Raj Jain answered with a picture. Take two users sharing a link of capacity C. Plot user one's rate across, and user two's up. On the diagonal line where the rates sum to C, the link is exactly full: efficient. Below it the link is underused, and above it, overloaded. On the forty-five degree line through the origin, the two get equal shares: fair. The goal is where the lines cross. Neither user can see the other. All each learns, every round, is one bit: was the link overloaded? And each changes its own rate by a rule. Adding the same amount to both rates moves the point along a forty-five degree line. Multiplying both by the same factor moves it along a line through the origin. Those two facts are the whole proof.

Here are four rules, each started with user one at a tenth of the link and user two at six tenths. Additive increase, multiplicative decrease. Each increase moves the point up the forty-five degree line until it crosses into overload; each halving pulls it toward the origin. The zig-zag closes in on the fairness line and oscillates around the goal. Additive increase and additive decrease slides up and down one forty-five degree line forever. The difference between the users never changes. Multiplicative both ways slides along one line through the origin. The ratio never changes: user two keeps six times user one's share. And multiplicative increase with additive decrease is worse than either: it drives user one to zero. Measured with Jain's fairness index, which is one when shares are equal, only AIMD reaches one.

The proof fits in four lines. Measure the unfairness by the difference between the two rates. An additive increase adds the same to both, so the difference does not change. A multiplicative decrease multiplies both by b, so it multiplies the difference by b: it halves it. The increases always carry the sum back into overload, so the halvings never stop, and after k of them the difference is b to the k times what it was: it goes to zero. Meanwhile the total rises to C, falls to half of C, and rises again: on average three quarters full, exactly the mean load we measured. Chiu and Jain proved more: among all linear rules, only additive increase with multiplicative decrease converges to fairness and efficiency from every starting point. Jacobson had chosen it by engineering intuition a year before; it was the only answer.

8The Mathis formulaGraduate3 min

In 1997 Matt Mathis and his colleagues asked how fast a Reno flow can go if the network drops a fraction p of its packets at random. In steady state, the window climbs from half of some peak W to W, one packet per round trip, then a loss halves it. Each tooth lasts W over two round trips. The packets sent in one tooth are the area under it: W over two round trips, at an average window of three quarters of W. That is three eighths of W squared. One of those packets is the loss, so three eighths W squared is one over p, and W is the square root of eight over three p. The rate is the average window, a packet's size each, per round trip. Out comes the Mathis formula: the packet size over the round trip, times the square root of three over two p. Throughput falls only as the square root of the loss rate, and directly as the round trip.

We tested the formula on our own TCP: a single Reno flow, a hundred-millisecond round trip, a link far faster than it can use, and random losses at five rates. On logarithmic axes the formula is a straight line of slope minus a half, and the measurements sit on it. At one loss in ten thousand, fourteen point three megabits a second, against fourteen point three predicted. At higher loss rates our flow does slightly better than the formula, because it learns about every lost packet at once, as selective acknowledgements allow, and recovers several in a single round trip. Padhye and colleagues extended the formula in 1998 to include timeouts, which matter when losses come in bursts. Look at what it says about long distance. Across the Atlantic, at a hundred and eight milliseconds and one loss in a thousand, Reno is limited to four megabits a second, on a link of a hundred. That is why Reno, in the hook, took thirty-five seconds.

The formula has a consequence nobody designed. Put two Reno flows on a twenty-megabit link, one with a twenty-millisecond round trip and the other further away. With equal round trips they split the link evenly. But a window grows by one packet per round trip, so the nearby flow grows ten times as often as one with ten times its round trip, while both suffer the same drops. At five times the round trip, the near flow gets two point three times as much. At ten times, thirty-two times as much: worse than one over the round trip, approaching one over its square, as Lakshman and Madhow showed for a shared drop-tail queue. AIMD is fair between equals. Between a user next door and a user across an ocean, it is not, and this is one of the reasons the next generation of algorithms grows with the clock, not with round trips.

9QueuesIndustry3 min

A router needs a queue, to absorb bursts. How long should it be? We gave one Reno flow, on a ten-megabit link with a hundred-millisecond round trip, buffers from a tenth of the bandwidth-delay product to eight times it. Too small, and every halving of the window drains the queue and leaves the link idle for a while: with a tenth of the product, the link is busy only seventy-eight percent of the time. With one full product, the queue never quite empties, and the link is ninety-nine percent busy. That was the rule of thumb from 1994. Beyond that, a bigger buffer buys no throughput at all. It buys delay. A loss-based TCP keeps growing its window until something is dropped, so it fills whatever buffer it is given. With eight times the product, every packet waits four hundred milliseconds in the queue, and the round trip is over half a second.

In 2010 Jim Gettys, at Bell Labs, noticed that his home network became unusable whenever he uploaded a file. His cable modem had a buffer of a few hundred packets, and an upload link of about a megabit a second. Two hundred and fifty-six packets of fifteen hundred bytes, at a megabit a second, is three seconds. Once an upload filled that queue, every packet from the house, a video call, a keystroke, a DNS lookup, waited three seconds behind it. He found the same everywhere: in home routers, modems, Wi-Fi drivers and phones. He called it bufferbloat. Memory had become cheap, so buffers grew, and nobody had noticed that a buffer sized for the fastest link a device might see was seconds long on the link it actually had.

The cure is to manage the queue, not just size it. Here a buffer of a thousand packets is shared by a Reno flow and a CUBIC flow on a ten-megabit link. With plain drop-tail, the flows fill it: more than a second of delay, all the time. Random early detection, by Sally Floyd and Van Jacobson in 1993, drops packets at random before the queue is full, with a probability that rises with the average length, so flows back off early. Delay falls to a quarter of a second. But RED has knobs that depend on the link, and in practice it was rarely switched on. CoDel, by Kathleen Nichols and Van Jacobson in 2012, has none. It measures how long each packet waited, and if even the shortest wait stays above five milliseconds for a hundred milliseconds, it starts dropping, faster and faster, until the queue drains. The mean delay is three milliseconds instead of a thousand. It gives up some throughput here, eighty-eight percent busy, because two flows with long round trips refill slowly; with more flows the loss disappears. CoDel and its descendant, fq_codel, now run in Linux and in many home routers.

10Modern congestion controlIndustry4 min

On fast, long paths Reno is hopeless: after a single loss on our hundred-megabit transatlantic path, climbing back by one packet per round trip takes over a minute and a half. Injong Rhee and his students replaced the line with a cubic. After a loss, CUBIC remembers the window where it happened, cuts to seven tenths of it, and follows a cubic curve in time: steep at first, flattening as it approaches the old window, where the last trouble was, and then accelerating beyond it to probe for more. Its growth depends on the clock, not on the number of round trips, so a distant flow grows as fast as a nearby one. CUBIC has been the default in Linux since 2006, and so in most of the servers on the Internet.

What is the ideal amount of data to have in flight? Plot two things against it. Below one bandwidth-delay product, the pipe is not full: the delivery rate grows with the data in flight, and the round trip is just propagation. Above it, the rate is stuck at the bottleneck's, and every extra packet only waits in a queue, lengthening the round trip. Leonard Kleinrock observed in 1979 that the best place to operate is the knee: exactly one bandwidth-delay product in flight, full rate at minimum delay. Loss-based congestion control cannot operate there. Its only signal is a loss, and a loss happens only when the buffer is full, so it lives at the cliff, at the far end of the queue, and pays the whole buffer in delay.

In 2016 Neal Cardwell, Yuchung Cheng, Van Jacobson and their colleagues at Google published BBR, a congestion control that aims for Kleinrock's point. Instead of reacting to losses, it builds a model of the path. The bottleneck bandwidth is estimated as the highest rate at which ACKs have come back in the last ten round trips. The propagation delay is the lowest round trip seen in the last ten seconds. BBR then paces its packets out at the estimated bandwidth, keeps about one bandwidth-delay product in flight, and every eight round trips sends a little faster for one round, to see if the pipe has grown, and a little slower for the next, to drain what that added. It starts up by doubling, like slow start, then drains the queue that built; and every ten seconds it briefly empties the pipe, to measure the delay again. Here is our BBR's window on the transatlantic path: the startup spike, then a steady cap at two pipes, while pacing keeps about one pipe actually in flight, with the dips of those re-measurements. And losses it does not treat as congestion at all.

We ran each algorithm alone on the transatlantic path, a hundred megabits a second, a buffer of one bandwidth-delay product. On a clean path, all three fill the pipe, about ninety-five megabits a second. But CUBIC keeps the queue eighty milliseconds long on average, and BBR eight: the same throughput at a tenth of the delay. Now lose one packet in a thousand at random, as a noisy radio link or a failing cable might. Reno falls to five and a half megabits, CUBIC to eight, as the Mathis formula says. BBR, which does not read random loss as congestion, keeps ninety-five. When Google switched its servers to BBR, it reported large gains on exactly such paths. That is the hook's answer: the eleven times was a theory of what a lost packet means.

11TCP as optimizationGraduate4 min

So far we have described congestion control as a set of rules. In 1997 and 1998 Frank Kelly, a mathematician at Cambridge, asked what problem those rules are solving. Take a network: here, two links in a row, each of capacity one, a long flow that crosses both, and two short flows that use one each. Give each flow a utility, a concave function of its rate saying how much it values bandwidth, and choose all the rates at once to maximize total utility, subject to no link carrying more than its capacity. This is network utility maximization. With logarithmic utilities, the solution has a name: proportional fairness. A rate is increased only if the percentage gain to some flows outweighs the percentage loss to others.

The problem decomposes, by the duality of Part 23. Attach a price to each link's capacity constraint: a Lagrange multiplier. The Lagrangian adds, for each link, its price times its overload. Now look at one flow. Its part of the Lagrangian is the log of its rate minus its rate times the total price along its path. It can maximize that alone: its best rate is one over the path price. And look at one link. It needs to know only its own load: if more is offered than it can carry, it raises its price a little; if less, it lowers it. This is gradient ascent on the dual problem. Every flow and every link acts on local information only, and together they converge to the global optimum.

We ran it on the two-link network. The rates swing at first, as prices overshoot, and then settle: the long flow at one third, each short flow at two thirds. Both links end up full, each with price one and a half. The long flow pays both prices, so it gets half the rate of a short flow. Compare max-min fairness, which raises everyone's rate together until a link fills: it gives all three a half. Proportional fairness carries more in total, five thirds against three halves, by charging the long flow for using two links. With three links in a row, the long flow gets a quarter. Which fairness is right is a question of values, not mathematics; what the mathematics says is which one a given algorithm is computing.

And here is the surprise. Real TCPs are this algorithm, in disguise. The price of a link is something the flows can observe: for Reno and CUBIC, the probability that a packet is dropped; for delay-based algorithms like Vegas, the time packets spend in the queue. Each flow adjusts its rate to the total price on its path. And each algorithm turns out to maximize a particular utility. Reno's, as Steven Low, Srinivas Kunniyur and Rayadurgam Srikant worked out, is approximately minus three halves over the round trip squared times the rate: setting its derivative equal to the loss rate gives back the Mathis formula, and the unfairness to long round trips is built into the utility itself. Vegas keeps a fixed number of its own packets queued, and is exactly proportionally fair. No one designed TCP this way. The engineering came first, and a decade later the theory explained what it had built.

12NamesDegree2 min

Programs name machines by names, not numbers. In the early ARPANET, every host downloaded one file, hosts dot t x t, listing every name; by 1983 that no longer scaled, and Paul Mockapetris designed the domain name system. Names form a tree. Thirteen root servers, answered by well over a thousand machines around the world, know who runs each top-level domain; each of those knows who runs each domain beneath it; and each domain answers for its own names. To find gutenberg dot org, a resolver asks a root server, which refers it to the servers for dot org; asks one of those, which refers it to Gutenberg's own servers; and asks them. The answer comes with a time to live: how many seconds it may be cached. Three round trips the first time; none for the next five minutes. The whole system is held together by caching, over UDP, one datagram each way.

Caching makes DNS fast, and a poisoned cache makes it dangerous. In 2008 Dan Kaminsky found a way to poison almost any resolver in seconds. The attacker asks your resolver about a name that cannot be in its cache, a random name under bank dot com. While the resolver waits for the real answer, the attacker sends forged ones, each claiming that the server for all of bank dot com is at the attacker's address. A reply is accepted if it carries the query's sixteen-bit identifier. If the real answer wins the race, the attacker simply asks for another random name, and races again. With a hundred forgeries a race, the expected number of races is six hundred and fifty-six: about a minute. Once one succeeds, every user of that resolver is sent to the attacker for everything at the bank. The emergency fix, coordinated in secret among vendors and released together in July 2008, randomized the source port of every query as well, sixteen more bits to guess: fifty days instead of a minute. The real fix is to sign the answers, with the public keys of Part 30, from the root down: DNSSEC.

13The web's transportIndustry3 min

TCP gives one ordered stream. A web page is not one thing. It is an HTML file, and then dozens of objects it refers to: images, scripts, style sheets. Ours has forty. The first web fetched each object over a new TCP connection, paying a handshake and a slow start every time. HTTP one point one kept connections open, but each could carry only one request at a time, so browsers opened six connections to each server, and six slow starts, and six congestion controllers competing with each other. HTTP/2, grown from Google's SPDY, put everything on one connection. Each object becomes a numbered stream, and the streams' frames are interleaved, so a small image need not wait behind a large one.

But the streams are interleaved inside one TCP byte stream, and TCP delivers bytes in order. Lose one packet, here belonging to stream two. Everything after it in the byte stream, the packets of streams one, three and four as well, is held by the receiver until the hole is filled, a round trip later. The four objects have nothing to do with each other, but TCP does not know that. It is the head-of-line blocking of the switch in the last part, moved into the transport: multiplexing over one ordered channel ties every stream to the slowest. Six separate connections have six separate orders, so on a lossy path old HTTP one point one can beat HTTP/2.

Why not fix TCP? Because TCP lives in every operating system kernel, and its header is read, and rewritten, by firewalls and other boxes all over the Internet, which break anything new. TCP had ossified. So Jim Roskind and Google's team built a new transport on top of UDP, which every box passes untouched. Standardized in 2021 as QUIC, it now carries a large share of the web. It merges the transport with TLS, the encryption of Part 30. A new connection needs one round trip before the request, instead of two or three, and a client returning to a server it knows can send its request in the very first packet. Inside, it has streams with independent orders, and loss recovery and congestion control much like TCP's, but every packet, including a retransmission, gets a fresh number, so Karn's ambiguity disappears. Almost all of it is encrypted, even most of the header, so no middlebox can come to depend on it. A connection is named by an identifier, not by addresses and ports, so a phone walking out of Wi-Fi onto a cellular network keeps its connections. And it runs in ordinary programs, so it can change as fast as browsers do.

14Caches at the edgeIndustry2 min

Everything in this part says that distance is expensive. Throughput falls as one over the round trip, and every handshake costs round trips. So the cheapest optimization of all is to make the path shorter. A content delivery network, starting with Akamai in 1998, keeps copies of popular content in thousands of places near users. Users are steered to a nearby copy in two ways: by DNS, answering each resolver with the address of a nearby site, with short times to live; or by anycast, announcing the same address from every site and letting BGP route each user to the closest. A request the nearby cache cannot answer goes back to the origin. So the question is how much a small cache can answer, and that depends on what people ask for.

In 1935 George Kingsley Zipf noticed that in any long text, the k-th most common word appears roughly in proportion to one over k. We can check it on the novels we have been counting all series. Four point six million words, fifty-eight thousand distinct ones; the commonest are the, and, to, of, a. Plot each word's count against its rank, both on logarithmic scales. The points fall on a line. Fitted between ranks ten and ten thousand, its slope is minus one point two two. Requests for web objects follow the same kind of law, as Lee Breslau and colleagues measured in 1999, with exponents a little below one: a few objects are requested constantly, and a long tail almost never. That shape is what makes caching work.

15The novels, over our TCPGraduate3 min

Back to the hook. Our TCP fetches the twenty-five megabytes of novels from Frankfurt, over a hundred megabits a second, a hundred and eight milliseconds, a buffer of one pipe, and one random loss in a thousand. Here are the first five seconds. All three start with slow start, doubling each round trip: about ten round trips, one second, to reach the pipe. Reno and CUBIC are knocked down by the first random loss before they reach it, and Reno then crawls back at one packet per round trip. CUBIC's curve climbs faster, and is knocked down again. BBR's startup overshoots to nearly three pipes, overflowing the buffer and losing fifteen hundred packets of its own, which it resends without slowing; then it drains and sits on the pipe until the novels are done, at three point two seconds.

Here is the account. Twenty-five million bytes, seventeen thousand packets, of which thirteen are lost at random. Reno takes thirty-five seconds, three hundred and twenty round trips, and resends only thirteen packets. CUBIC takes twenty-four. BBR takes three point two, twenty-nine round trips, and resends sixteen hundred packets, almost all of them dropped by its own startup. The physics allows two point two. The last column is the key. On the same path with no random loss, all three take three point two seconds: a dozen round trips of slow start, then the pipe. The whole factor of eleven comes from how each algorithm interprets thirteen lost packets. Reno reads each as a full queue and halves; on a path where losses are noise, that is the wrong theory, and it costs thirty seconds.

The ledger gets row fourteen. The novels, fetched from Frankfurt over our TCP with CUBIC, the default on Linux, in twenty-four seconds, then counted under PebbleOS, as in row twelve, in under three. Twenty-seven seconds in all, and ninety percent of it is the network. For the first time in this series, computing is not what limits the Job: distance is. With BBR the fetch takes three seconds; with Reno, thirty-five. The next parts spread the Job over many machines, and every one of them will pay this toll to talk to the others.

16Frontier: can congestion control be fair?Research1 min

Half a century after the alternating bit, congestion control still has open questions, and in 2022 it acquired an impossibility theorem. To keep queues short, modern algorithms react to delay rather than waiting for loss. Each, in steady state, keeps the queueing delay inside some small range. But some delay has nothing to do with congestion. Wi-Fi and cellular links deliver ACKs in batches; schedulers hold packets back; two paths differ by a few milliseconds. Venkat Arun, Mohammad Alizadeh and Hari Balakrishnan proved that if this non-congestive delay can exceed the range an algorithm converges to, there is a network in which one of two flows gets an arbitrarily small share. The reason is simple to state. A flow cannot tell its own queue apart from delay it cannot see the cause of. Add a little noise to one flow's path, and it believes the link is busier than it is, and yields. Low delay, full use of the link, and fairness despite jitter: you can choose two.

Recap, problems, and where this comes backAll tracks3 min

What we built in this part. Reliable delivery from nothing: stop-and-wait, the alternating bit, and windows, with the exact number of sequence numbers they need. TCP's handshake, its cookies and its timers. The collapse of 1986, reproduced, and Jacobson's cure, with Chiu and Jain's proof that it is fair. The Mathis formula, measured; queues, bufferbloat and CoDel; CUBIC and BBR; and Kelly's theorem that all of this is an optimization algorithm, with prices on links. Then names, the web over QUIC, and caches shaped by Zipf's law.

Where this comes back. Part 38 asks machines to agree over a network that loses and delays messages, where a timeout can never tell a dead machine from a slow one. Part 39 replicates data across these round trips, and runs the Job on many machines. Part 42 builds the browser on top of QUIC and TLS. Part 45 rents load balancers and content networks by the hour. And Parts 49 and 50 find retries, backoff and CoDel's ideas inside every large service.

In practice. On long, fast paths, make sure socket buffers can hold a bandwidth-delay product, and try BBR, which on Linux is one setting. At home, turn on fq_codel or CAKE, shaping just below the link's rate, and bufferbloat disappears. Reuse connections: every new one costs round trips and a slow start. To see what TCP is doing, ss with the t and i flags shows each connection's window, round trip and retransmissions, and Wireshark draws its sequence numbers over time. And choose DNS times to live on purpose.

Six problems, with full solutions in the part's notes. Pause on any of them. The fifth is a build problem: add delayed acknowledgements to our TCP, as real receivers do, and see what breaks. The last, marked with a star, is a research problem: how much queueing delay must any algorithm accept to stay fair when one flow's path is noisy? Measure the curve, and compare it with the starvation theorem.

Next time, Part 38: Distributed systems, agreement. Over the lossy network of this part, two generals can never be sure they agree, and with no clock in common, even the order of events is a matter of definition. Fischer, Lynch and Paterson proved that consensus is impossible when messages can be arbitrarily slow. Paxos and Raft reach it anyway, and we build Raft on our network and try to break it. Part 38, Agreement.

The books and papers this part follows are on screen and in the notes. Thank you for watching.

Where it goes next. Part 38 asks machines to agree over this network, where a timeout cannot tell a dead machine from a slow one, and Part 39 replicates data across its round trips. Part 42 builds the browser on QUIC and TLS, Part 45 rents load balancers and content networks, and retries, backoff and CoDel's idea return inside large services in Parts 49 and 50.

Key results

The part's results in one place, for revision.

Stop-and-wait\(\displaystyle U=\frac{L/R}{\mathrm{RTT}+L/R}\)
Sequence space\(\displaystyle \text{Go-Back-N: } W\le S-1,\qquad\allowbreak \text{Selective }\allowbreak \text{Repeat: } W\le S/2\)
The timer\(\displaystyle \mathrm{RTO}=\mathrm{SRTT}+4\cdot\mathrm{RTTVAR}\)
AIMD is fair\(\displaystyle x_1-x_2\ \mapsto\ b^{k}(x_1-x_2)\to 0 \quad\allowbreak \text{after } k \text{ decreases}\)
The Mathis formula\(\displaystyle \text{rate}\approx\frac{\mathrm{MSS}}{\mathrm{RTT}}\sqrt{\frac{3}{2p}}\)
Kelly's problem\(\displaystyle \max\sum_r \log x_r\ \text{ s.t. }\sum_{r\ni l}x_r\le c_l;\quad\allowbreak x_r=\frac{1}{\sum_{l\in r}p_l}\)

Try it

Lab 37 · Only AIMD is fair, and TCP is an optimizer

Start two users at unequal rates on one link and run AIMD, AIAD, MIMD and MIAD from Chiu and Jain's model: check that an additive step keeps the difference, a multiplicative step keeps the ratio, and only AIMD reaches Jain's index 1. Then solve Kelly's utility maximization on two links by dual ascent on prices and compare it with the closed form (1/3, 2/3, 2/3).

Figure produced by Lab 37: Only AIMD is fair, and TCP is an optimizer
Produced by the lab below, seed 0, in 0.2 s.
python -m videos.cs.labs 37 needs numpy, scipy, matplotlib · download lab37.py · source on GitHub
start (user 1, user 2)                    (0.177, 0.581)   Jain's index 0.779
AIMD: after 200 rounds                    (0.380, 0.380)   fairness 1.000   load 0.77
AIAD: after 200 rounds                    (0.297, 0.701)   fairness 0.866   load 1.03
MIMD: after 200 rounds                    (0.123, 0.403)   fairness 0.779   load 0.76
MIAD: after 200 rounds                    (0.000, 1.129)   fairness 0.500   load 1.06
AIMD: decreases, and the difference left  21 halvings; 0.404 x 0.5^21 = 1.9e-07
dual ascent: rates (long, a, b)           0.333, 0.667, 0.667   closed form 0.333, 0.667, 0.667
dual ascent: link prices                  1.500, 1.500   closed form 1.5, 1.5
max-min fair rates                        0.500, 0.500, 0.500   total 1.500 against 1.667

Adding moves the pair along a 45-degree line and multiplying along a line through the origin, so only additive increase with multiplicative decrease closes the gap; and rates that answer link prices settle at the proportionally fair optimum, which carries more in total than max-min fairness.
The code (81 lines; it asserts its own result)
"""Lab 37: run Chiu and Jain's four rules from a random start, and solve Kelly's problem with link prices."""

from videos.coursekit import labs

import numpy as np

from explainer.cs.net import cc

TITLE = "Only AIMD is fair, and TCP is an optimizer"
GOAL = ("Start two users at unequal rates on one link and run AIMD, AIAD, MIMD and MIAD from Chiu and Jain's model: "
        "check that an additive step keeps the difference, a multiplicative step keeps the ratio, and only AIMD "
        "reaches Jain's index 1. Then solve Kelly's utility maximization on two links by dual ascent on prices and "
        "compare it with the closed form (1/3, 2/3, 2/3).")
TASKS = [
    "Change AIMD's decrease factor b from 0.5 to 0.9. How many decreases does it take to halve the unfairness now?",
    "Give the long flow a third link (routes 'long': ['L1', 'L2', 'L3']). What rates and prices does dual ascent find?",
    "Raise the dual step from 0.05 to 2.5. What happens to the prices, and what does that say about gain in a control loop?",
]
RULES = ("AIMD", "AIAD", "MIMD", "MIAD")


def run(seed=0):
    rng = np.random.default_rng(seed)
    x0 = (float(rng.uniform(0.05, 0.25)), float(rng.uniform(0.5, 0.8)))
    lab = labs.Lab()
    lab.row("start (user 1, user 2)", f"({x0[0]:.3f}, {x0[1]:.3f})   Jain's index {cc.jain(x0):.3f}")
    out = {rule: cc.chiu_jain(rule, x0=x0, steps=200, a=0.03, b=0.5, m=1.15) for rule in RULES}
    for rule in RULES:
        r = out[rule]
        x1, x2 = r["trajectory"][-1]
        lab.row(f"{rule}: after 200 rounds", f"({x1:.3f}, {x2:.3f})   fairness {r['fairness']:.3f}   load {r['efficiency']:.2f}")
    diff0, ratio0 = x0[1] - x0[0], x0[1] / x0[0]
    t = np.array(out["AIMD"]["trajectory"])
    halvings = int(np.sum(t[1:].sum(axis=1) < t[:-1].sum(axis=1)))
    assert abs((t[-1, 1] - t[-1, 0]) - diff0 * 0.5 ** halvings) < 1e-9, "each halving halves the difference, exactly"
    assert out["AIMD"]["fairness"] > 0.999 and 0.7 < out["AIMD"]["efficiency"] < 0.82, "AIMD: fair, about 3/4 full"
    t = np.array(out["AIAD"]["trajectory"])
    assert np.allclose(t[:, 1] - t[:, 0], diff0), "AIAD never changes the difference"
    t = np.array(out["MIMD"]["trajectory"])
    assert np.allclose(t[:, 1] / t[:, 0], ratio0), "MIMD never changes the ratio"
    assert out["AIAD"]["fairness"] < 0.97 and out["MIMD"]["fairness"] < 0.9
    assert out["MIAD"]["fairness"] < 0.55 and out["MIAD"]["trajectory"][-1][0] < 1e-9, "MIAD starves user 1"
    lab.row("AIMD: decreases, and the difference left", f"{halvings} halvings; {diff0:.3f} x 0.5^{halvings} = {diff0 * 0.5 ** halvings:.1e}")

    # Kelly: maximize the sum of log rates; a long flow crosses both links, a short flow uses each one
    routes, caps = {"long": ["L1", "L2"], "a": ["L1"], "b": ["L2"]}, {"L1": 1.0, "L2": 1.0}
    num = cc.num_dual(routes, caps, step=0.05, iters=3000)
    fair = cc.max_min(routes, caps)
    x, p = num["x"], num["p"]
    lab.row("dual ascent: rates (long, a, b)", f"{x['long']:.3f}, {x['a']:.3f}, {x['b']:.3f}   closed form 0.333, 0.667, 0.667")
    lab.row("dual ascent: link prices", f"{p['L1']:.3f}, {p['L2']:.3f}   closed form 1.5, 1.5")
    lab.row("max-min fair rates", f"{fair['long']:.3f}, {fair['a']:.3f}, {fair['b']:.3f}   total {sum(fair.values()):.3f} against {sum(x.values()):.3f}")
    assert abs(x["long"] - 1 / 3) < 0.01 and abs(x["a"] - 2 / 3) < 0.01 and abs(x["b"] - 2 / 3) < 0.01
    assert abs(p["L1"] - 1.5) < 0.03 and abs(p["L2"] - 1.5) < 0.03, "the prices are the Lagrange multipliers"
    assert all(abs(v - 0.5) < 1e-9 for v in fair.values()) and sum(x.values()) > sum(fair.values()) + 0.15
    lab.note = ("Adding moves the pair along a 45-degree line and multiplying along a line through the origin, so only "
                "additive increase with multiplicative decrease closes the gap; and rates that answer link prices "
                "settle at the proportionally fair optimum, which carries more in total than max-min fairness.")

    fig, ax = labs.figure(2, size=(11, 4.4))
    ax[0].plot([0, 1], [1, 0], color=labs.MUTED, ls="--", lw=1, label="efficient: x1 + x2 = C")
    ax[0].plot([0, 1], [0, 1], color=labs.GREY, ls=":", lw=1.2, label="fair: x1 = x2")
    for rule, color in zip(RULES, (labs.GREEN, labs.BLUE, labs.GOLD, labs.RED)):
        t = np.array(out[rule]["trajectory"])
        ax[0].plot(t[:, 0], t[:, 1], color=color, lw=1.3, label=rule)
    ax[0].scatter(*x0, color=labs.INK, s=30, zorder=3)
    ax[0].set(title="Chiu and Jain's plane: four rules from one start", xlabel="user 1's rate", ylabel="user 2's rate",
              xlim=(0, 1.2), ylim=(0, 1.2), aspect="equal")
    ax[0].legend(loc="upper right")
    h = num["history"]
    its = [r["iter"] for r in h]
    ax[1].plot(its, [r["x"]["long"] for r in h], color=labs.RED, label="long flow (both links)")
    ax[1].plot(its, [r["x"]["a"] for r in h], color=labs.BLUE, label="short flow on link 1")
    ax[1].plot(its, [r["p"]["L1"] for r in h], color=labs.GOLD, label="price of link 1")
    for y in (1 / 3, 2 / 3, 1.5):
        ax[1].axhline(y, color=labs.MUTED, ls="--", lw=0.9)
    ax[1].set(title="Dual ascent: prices rise until demand fits", xlabel="iteration", ylabel="rate, or price",
              xlim=(0, 1500), ylim=(0, 2.2))
    ax[1].legend(loc="upper right")
    lab.fig = fig
    return lab

Now change it

  1. Change AIMD's decrease factor b from 0.5 to 0.9. How many decreases does it take to halve the unfairness now?
  2. Give the long flow a third link (routes 'long': ['L1', 'L2', 'L3']). What rates and prices does dual ascent find?
  3. Raise the dual step from 0.05 to 2.5. What happens to the prices, and what does that say about gain in a control loop?

Problems, with solutions

Try each problem before opening its solution.

  1. Sequence space. Prove that Selective Repeat with sequence numbers mod S is correct iff W ≤ S/2, and Go-Back-N iff W ≤ S − 1, on a FIFO channel that may lose packets.

    Solution

    Sufficiency for Selective Repeat: when the receiver expects packets r, …, r + W − 1, every packet the sender can still send lies in [r − W, r + W − 1], because the sender's base is at least r − W (the receiver has acknowledged up to r − 1, and the sender cannot have sent beyond its base + W − 1 before seeing those ACKs) and at most r. That interval has 2W ≤ S numbers, so mod S they are distinct; a packet whose number falls in the receiver's window is the packet it seems to be, and one below it is an old duplicate, acknowledged again and discarded. Necessity: let the receiver accept 0, …, W − 1 and every ACK be lost; the sender resends 0, whose number mod S equals S, inside the new window [W, 2W − 1] when 2W > S, so it is accepted as packet S. For Go-Back-N the receiver's window is a single number r, and the sender's possible numbers lie in [r − W, r]: W + 1 numbers, distinct iff W + 1 ≤ S. With W = S, all ACKs lost and packet 0 resent, the receiver expecting packet S accepts it. Our tests: S = 8, Go-Back-N W = 7 and Selective Repeat W = 4 correct in 10 of 10 runs, W = 8 and W = 5 in 0.

  2. Mathis, with timeouts. Derive the Mathis formula; then redo it when every loss is detected only by a timeout of 2 RTT.

    Solution

    In steady state the window rises linearly from W/2 to W over W/2 round trips, so a cycle delivers (W/2)(3W/4) = 3W²/8 packets, one of which is lost: 3W²/8 = 1/p, W = √(8/(3p)), and the rate is (3W/4)·MSS/RTT = (MSS/RTT)√(3/(2p)). If each loss instead stalls for a timeout of 2 RTT and restarts from a window of one, each cycle is a slow start to W/2 (log₂(W/2) round trips, about W/2 packets), then a linear climb from W/2 to W (3W²/8 packets in W/2 round trips), then the 2-RTT stall. Packets per cycle ≈ 3W²/8 + W/2 = 1/p; time per cycle ≈ W/2 + log₂(W/2) + 2 round trips. For small p, W ≈ √(8/(3p)) still, and the rate falls by the factor (W/2)/(W/2 + log₂ W + 1), which matters when W is small: at p = 0.01 (W ≈ 16) the rate drops by about half. This is the regime Padhye et al. modelled in 1998.

  3. The four rules. Show that AIAD and MIMD preserve, respectively, the difference and the ratio of two users' rates; prove AIMD converges for any a > 0 and 0 < b < 1.

    Solution

    Under AIAD both rates change by the same ±a each round (until one hits zero), so x₂ − x₁ is invariant; under MIMD both are multiplied by the same factor, so x₂/x₁ is invariant. Neither approaches the fairness line from an unfair start. Under AIMD, increases leave d = x₂ − x₁ unchanged and decreases multiply it by b. The sum s grows by 2a in each increase round, so from any point it exceeds C within ⌈C/(2a)⌉ rounds; hence decreases occur infinitely often, and after k of them |d| = bᵏ|d₀| → 0. After convergence s oscillates between about bC and C + 2a, so efficiency tends to the band [b, 1]: for b = 1/2 a mean load of about 3/4, our 0.78.

  4. Three links in a row. Solve Kelly's problem with log utilities on three links of capacity 1 in a row, with a long flow over all three and a short flow on each, by hand, and check the prices.

    Solution

    By symmetry every link has the same price p, so a short flow sends 1/p and the long flow 1/(3p). Each link is full: 1/p + 1/(3p) = 1, so p = 4/3, the short flows get 3/4 and the long flow 1/4. KKT: ∂/∂x of Σ log x is 1/x, which must equal the path price: 1/(3/4) = 4/3 = p for a short flow, 1/(1/4) = 4 = 3p for the long one. Total 9/4 = 2.25, against max-min's four flows at 1/2, total 2. Our dual ascent: 0.250 and 0.750.

  5. Build: delayed ACKs. Add delayed acknowledgements (one ACK per two segments, or after 40 ms) to our TCP. What happens to slow start, to Mathis's constant, and to BBR's bandwidth estimate?

    Solution

    Solution sketch. In tcp.py the receiver acknowledges each packet as it leaves the bottleneck; buffer every second one (with a timer) and acknowledge both, and let a cumulative ACK credit the window for both packets (or, as RFC 5681 allows, by at most one, which is what makes the difference). Counting ACKs, slow start grows by 1.5× per round trip instead of 2× and congestion avoidance by half a packet per round trip, so the Mathis constant √(3/2) ≈ 1.22 becomes √(3/4) ≈ 0.87 (Mathis et al. give this as b = 2). Appropriate byte counting (RFC 3465) restores both. BBR's delivery-rate samples become burstier, since ACKs arrive two packets at a time; its max filter makes it overestimate slightly, so it pushes a little more into the queue.

  6. ★ Research: the delay–fairness trade-off. On our dumbbell with in-order ACK jitter of up to D on one flow, find the least mean queueing delay any algorithm you can design needs to keep two flows' Jain index above 0.9; plot it against D, and compare with the 2022 starvation bound.

    What is known. Arun, Alizadeh and Balakrishnan prove that a delay-convergent algorithm, one whose queueing delay converges to a range of width δ(C), can be made to starve when non-congestive delay exceeds δ; so fairness under jitter D needs either an equilibrium delay range wider than D (and so queues of at least about D) or a signal other than delay (loss, ECN). Our measurements give points: Vegas (queueing about 4.5 packets) falls to a share of 7% at D = 40 ms; Reno keeps 36% but fills the buffer. What is open is the exact curve: for each D, the minimum delay compatible with a given fairness, and algorithms that meet it. A starting point is an algorithm that deliberately oscillates its delay over a range larger than D (as Copa's mode switching does) and measures its share through the oscillation. Report Jain's index and mean queue for D = 0, 5, 10, 20, 40 ms.

Notes and sources

Glossary

  • transport layer: end-to-end delivery between programs; port: a 16-bit number naming a program's endpoint.
  • UDP: datagrams with ports and a checksum, no promises; TCP: a reliable, ordered, flow- and congestion-controlled byte stream.
  • ARQ: automatic repeat request, reliability by acknowledgement and retransmission; alternating-bit protocol: stop-and-wait with one-bit sequence numbers.
  • sliding window: up to W packets sent and unacknowledged; Go-Back-N, Selective Repeat: resend from the loss on, or only the loss.
  • cumulative ACK: the next byte expected; SACK: selective acknowledgement of blocks beyond a gap.
  • three-way handshake: SYN, SYN+ACK, ACK; SYN cookie: connection state encoded in the server's initial sequence number; TIME_WAIT: 2 MSL of reserving a closed connection's four numbers.
  • flow control: the receiver's advertised window; congestion window: the sender's estimate of what the network can hold.
  • RTO: retransmission timeout, SRTT + 4·RTTVAR; Karn's rule: no RTT samples from retransmissions.
  • congestion collapse: a network busy carrying retransmissions while goodput falls; goodput: new data delivered per second.
  • slow start, congestion avoidance, fast retransmit, fast recovery: Jacobson's mechanisms; ACK clocking: sending one packet per ACK received.
  • AIMD: additive increase, multiplicative decrease; Jain's fairness index: (Σx)² / (n Σx²).
  • Mathis formula: TCP throughput ≈ (MSS/RTT)√(3/(2p)); RTT unfairness: shorter round trips win more.
  • bufferbloat: excessive buffering that adds delay without throughput; AQM: active queue management (RED, CoDel); ECN: explicit congestion notification, marking instead of dropping.
  • CUBIC, BBR, Vegas, DCTCP: congestion controls by cubic growth in time, by a model of bandwidth and delay, by delay, and by ECN marks in data centres.
  • network utility maximization: rates maximizing Σ U(x) under link capacities; proportional fairness: its solution for log utilities; max-min fairness: no rate can rise without lowering a smaller one.
  • DNS: the hierarchical, cached name system; TTL (DNS): how long an answer may be cached; cache poisoning: forging answers into a resolver's cache; DNSSEC: signed DNS answers.
  • head-of-line blocking: independent data delayed behind a loss in a shared ordered channel; QUIC: a transport over UDP with streams, built-in TLS 1.3 and connection IDs; 0-RTT: sending data in the first packet.
  • CDN: content delivery network; anycast: one address announced from many sites; Zipf's law: frequency ∝ rank^−s; Che approximation: an LRU cache's hit rate from a characteristic time.
  • starvation (congestion control): a flow receiving an arbitrarily small share; L4S: low-latency, low-loss, scalable throughput with early ECN marking.

Sources

  • J. F. Kurose and K. W. Ross, Computer Networking: A Top-Down Approach, ch. 2–3; L. L. Peterson and B. S. Davie, Computer Networks: A Systems Approach, ch. 5–6.
  • W. R. Stevens, TCP/IP Illustrated, vol. 1; I. Grigorik, High Performance Browser Networking.
  • R. Srikant and L. Ying, Communication Networks: An Optimization, Control and Stochastic Networks Perspective; F. Kelly and E. Yudovina, Stochastic Networks.
  • K. A. Bartlett, R. A. Scantlebury and P. T. Wilkinson, "A Note on Reliable Full-Duplex Transmission over Half-Duplex Links", CACM (1969).
  • V. Cerf and R. Kahn, "A Protocol for Packet Network Intercommunication", IEEE Trans. Communications (1974); J. Postel, RFC 768 (1980) and RFC 793 (1981).
  • J. Nagle, "Congestion Control in IP/TCP Internetworks", RFC 896 (1984).
  • P. Karn and C. Partridge, "Improving Round-Trip Time Estimates in Reliable Transport Protocols", SIGCOMM (1987).
  • V. Jacobson, "Congestion Avoidance and Control", SIGCOMM (1988).
  • D.-M. Chiu and R. Jain, "Analysis of the Increase and Decrease Algorithms for Congestion Avoidance in Computer Networks", Computer Networks and ISDN Systems (1989).
  • S. Floyd and V. Jacobson, "Random Early Detection Gateways for Congestion Avoidance", IEEE/ACM ToN (1993).
  • L. S. Brakmo and L. L. Peterson, "TCP Vegas: End to End Congestion Avoidance on a Global Internet", IEEE JSAC (1995).
  • D. J. Bernstein, "SYN cookies" (1996); RFC 4987 (2007).
  • M. Mathis, J. Semke, J. Mahdavi and T. Ott, "The Macroscopic Behavior of the TCP Congestion Avoidance Algorithm", CCR (1997); J. Padhye, V. Firoiu, D. Towsley and J. Kurose, "Modeling TCP Throughput", SIGCOMM (1998).
  • T. V. Lakshman and U. Madhow, "The Performance of TCP/IP for Networks with High Bandwidth-Delay Products and Random Loss", IEEE/ACM ToN (1997).
  • F. Kelly, A. Maulloo and D. Tan, "Rate Control for Communication Networks: Shadow Prices, Proportional Fairness and Stability", J. Operational Research Society (1998); S. H. Low and D. E. Lapsley, "Optimization Flow Control", IEEE/ACM ToN (1999); S. H. Low, "A Duality Model of TCP and Queue Management Algorithms", IEEE/ACM ToN (2003).
  • G. Appenzeller, I. Keslassy and N. McKeown, "Sizing Router Buffers", SIGCOMM (2004).
  • S. Ha, I. Rhee and L. Xu, "CUBIC: A New TCP-Friendly High-Speed TCP Variant", OSR (2008); RFC 9438 (2023).
  • M. Alizadeh et al., "Data Center TCP (DCTCP)", SIGCOMM (2010).
  • J. Gettys and K. Nichols, "Bufferbloat: Dark Buffers in the Internet", ACM Queue (2011); K. Nichols and V. Jacobson, "Controlling Queue Delay", ACM Queue (2012).
  • N. Cardwell, Y. Cheng, C. S. Gunn, S. H. Yeganeh and V. Jacobson, "BBR: Congestion-Based Congestion Control", ACM Queue (2016); L. Kleinrock, "Power and Deterministic Rules of Thumb for Probabilistic Problems in Computer Communications", ICC (1979).
  • P. Mockapetris, RFC 1034/1035 (1987); D. Kaminsky, "Black Ops 2008" (2008).
  • A. Langley et al., "The QUIC Transport Protocol: Design and Internet-Scale Deployment", SIGCOMM (2017); J. Iyengar and M. Thomson, RFC 9000 (2021).
  • L. Breslau, P. Cao, L. Fan, G. Phillips and S. Shenker, "Web Caching and Zipf-like Distributions", INFOCOM (1999); H. Che, Y. Tung and Z. Wang, "Hierarchical Web Caching Systems: Modeling, Design and Experimental Results", IEEE JSAC (2002).
  • K. Winstein and H. Balakrishnan, "TCP ex Machina: Computer-Generated Congestion Control", SIGCOMM (2013); V. Arun, M. T. Arashloo, A. Saeed, M. Alizadeh and H. Balakrishnan, "Toward Formally Verifying Congestion Control Behavior", SIGCOMM (2021).
  • V. Arun, M. Alizadeh and H. Balakrishnan, "Starvation in End-to-End Congestion Control", SIGCOMM (2022).
  • B. Briscoe et al., "Low Latency, Low Loss, and Scalable Throughput (L4S) Internet Service: Architecture", RFC 9330 (2023).
About this partfrom its README

Part 37 of a sixty-one-part course in computer science (see the series plan and the syllabus), the second part of Act VII, Many Machines. IP loses, reorders and duplicates packets; TCP turns that into a reliable byte stream. In October 1986 the Internet's throughput fell a thousandfold, and Van Jacobson's cure, additive increase and multiplicative decrease, turned out to be the only linear rule that is fair, and a distributed algorithm for an optimization problem. The novels arrive over our own TCP on a lossy transatlantic link: ledger row 14.

The instruments are in explainer/cs/net/ (tested in tests/test_cs37_transport.py):

  • rdt.py: reliable delivery from scratch, event-driven: stop-and-wait (the alternating-bit protocol with one-bit sequence numbers), Go-Back-N and Selective Repeat, over a channel with delay, rate, loss, duplication and reordering; sequence numbers modulo 2^bits, so a protocol with too few fails visibly.
  • tcp.py: a packet-level simulator of flows sharing a bottleneck (the "dumbbell"): per-packet ACKs (as with SACK), RACK-style loss detection by transmission order, fast recovery, Jacobson/Karels RTO with Karn's rule; congestion control fixed (the TCPs of 1986: fixed window, fixed timer, go-back-n), reno, cubic (RFC 9438), vegas and bbr (BBRv1: startup, drain, gain cycling, PROBE_RTT, pacing); queues drop-tail, RED or CoDel; random loss; and in-order, non-congestive ACK jitter per flow. Also the Mathis formula and Jain's index.
  • cc.py: Chiu and Jain's two-user model under AIMD, AIAD, MIAD and MIMD; Kelly's network utility maximization with log utilities, by dual (sub)gradient ascent on link prices; max-min fairness by progressive filling.
  • app.py: an iterative DNS resolver with TTL caching; the odds of Kaminsky's cache poisoning; a packet-level page load over HTTP/1.1 (six connections), HTTP/2 (one ordered connection) and QUIC (ordering per stream); Zipf fitting; an LRU cache and Che's approximation.
Chapter notes
  • Hook. The novels (24,971,555 bytes, 17,104 packets) from Frankfurt to San Francisco: 100 Mb/s, RTT 108 ms, one packet in 1,000 lost. Reno 34.9 s, CUBIC 24.2 s, BBR 3.2 s; the physics 2.2 s. Their windows over time.
  • 1. The transport problem. 10,000 datagrams across a channel like IP's: 109 lost, 18 duplicated, 284 overtaken. Ports and the four-number connection name; UDP's 8-byte header; the two contracts; the end-to-end argument.
  • 2. Reliability from scratch. Stop-and-wait and timers; lost ACKs and the alternating bit (Bartlett, Scantlebury and Wilkinson, 1969): 20 of 20 runs correct on a FIFO channel with 10% loss, 0 of 20 once 20% of packets are delayed (the first error at position 8, packet 6 delivered again). Utilization (L/R)/(RTT + L/R), measured to four digits; across the Atlantic at 1 Gb/s, 0.11 Mb/s.
  • 3. Sliding windows. The window and ACK clocking; Go-Back-N and Selective Repeat. Utilization against window (RTT 100 ms, 1,000 packets/s): on the formula with no loss; at 2% loss and W = 128, Go-Back-N 0.14 (4,937 retransmissions for 2,000 packets), Selective Repeat 0.42 (88). The sequence-space theorem, proved and tested at its edge with S = 8: Go-Back-N W = 7 always correct, W = 8 never; Selective Repeat W = 4 always, W = 5 never.
  • 4. TCP. The header; the three-way handshake and random initial sequence numbers (first byte after 2 RTT, 216 ms). SYN floods and Bernstein's cookies (5 bits of time, 3 of MSS, 24 of keyed hash; one built). Teardown and TIME_WAIT (60 s: at most 546 connections a second to one server port). Flow control: a 64 KB window caps the Atlantic at 4.9 Mb/s; window scaling; buffers of a bandwidth-delay product (1.35 MB).
  • 5. Timers that learn. 402 RTT samples from a shared bottleneck (109 to 348 ms). RFC 793's β·SRTT against Jacobson and Karels's SRTT + 4·RTTVAR: β = 1.3 fires early 15 times; β = 2 never, but waits 495 ms on average; Jacobson once, waiting 336 ms. Karn's rule and backoff; timestamps.
  • 6. Congestion collapse. October 1986, LBL to UC Berkeley, 32 kb/s to 40 b/s. Reproduced: four flows on 2 Mb/s with fixed windows and a fixed 200 ms timer: goodput rises to 1.94 Mb/s, then falls to 1.11 once the windows exceed pipe + buffer, with the link 99.9% busy and 11,189 retransmissions a minute; Reno 1.94 at every load. Conservation of packets, ACK clocking, the congestion window, slow start; the sawtooth (utilization 99%).
  • 7. AIMD. Chiu and Jain's phase plane; trajectories from (0.1, 0.6): AIMD reaches Jain's index 1.000 (mean load 0.78), AIAD keeps the difference (0.81), MIMD the ratio (0.66), MIAD starves one user (0.50). The four-line proof.
  • 8. The Mathis formula. Derived from one tooth: rate = (MSS/RTT)·√(3/(2p)). Measured at RTT 100 ms: 14.30 Mb/s at p = 10⁻⁴ against 14.31; 4.77 against 4.52 at 10⁻³; 1.73 against 1.43 at 10⁻² (per-packet ACKs recover several losses a round trip). RTT unfairness: 20 ms against 50, 100 and 200 ms: ratios 2.3, 5.5, 31.9.
  • 9. Queues. Buffer sizes from 0.1 to 8 BDP: utilization 78% to 99%, then only delay (426 ms at 8 BDP). Bufferbloat (Gettys, 2010). A 1,000-packet buffer: drop-tail 1,051 ms mean, RED 236 ms, CoDel 2.9 ms (at 88% utilization). Appenzeller, Keslassy and McKeown: with 64 flows, BDP/8 keeps 97.6% against 98.5%.
  • 10. Modern congestion control. CUBIC's curve. Kleinrock's operating point. BBR's model and our BBR's window. Alone on the transatlantic path: Reno 97.3, CUBIC 97.3, BBR 94.1 Mb/s, with mean queues 32, 81 and 8 ms; with 0.1% random loss 5.5, 8.0 and 94.8. BBR beside CUBIC on 50 Mb/s: 46.9 / 1.3 (buffer BDP/4), 43.9 / 2.4 (BDP), 30.4 / 17.9 (4 BDP). Vegas alone 9.7 Mb/s with 4.5 packets queued; beside Reno, 0.0 against 9.7. DCTCP, BBRv2 and v3.
  • 11. TCP as optimization. Kelly's problem; the dual decomposition into link prices and flow rates; dual ascent on two links: long flow 1/3, short flows 2/3, prices 1.5 (max-min: 1/2 each; totals 5/3 against 3/2); three links: 1/4 and 3/4. Reno's utility −3/(2·RTT²·x), Vegas's α log x.
  • 12. Names. The DNS tree; a day of 50,000 lookups: 56% cache hits, 0.88 round trips per lookup instead of 3. Kaminsky (2008): 656 expected races with a fixed port (a minute), 43 million with random ports (50 days); DNSSEC.
  • 13. The web's transport. HTTP/1.0, 1.1, 2; head-of-line blocking in one TCP stream. A 41-object page over 108 ms: mean object time HTTP/2 209 → 336 ms from 0 to 5% loss, QUIC 209 → 227 (handshakes not modelled). QUIC: 1-RTT and 0-RTT setup (432, 324, 216, 108 ms to the first byte), fresh packet numbers, encryption, connection IDs.
  • 14. Caches at the edge. CDNs, DNS steering and anycast. Zipf's law on the novels: 4,609,954 words, 57,895 distinct, s = 1.22 on ranks 10 to 10,000. LRU on the words as requests: 10.2%, 47.2%, 78.6%, 95.8% for caches of 10 to 10,000 words, above Che's independent-reference prediction (7.6, 37.6, 69.7, 93.3) because words come in bursts.
  • 15. The novels, over our TCP. The first five seconds of each window. The account: Reno 34.9 s (323 round trips, 13 resent), CUBIC 24.2 s (224), BBR 3.2 s (29, 1,593 resent from its own startup); all three 3.17 s with no loss. Ledger row 14: fetched with CUBIC (24.2 s) and counted under PebbleOS (2.7 s), 26.8 s, 90% of it network.
  • 16. Frontier: can congestion control be fair? The starvation theorem (Arun, Alizadeh and Balakrishnan, 2022). Measured, two flows on 20 Mb/s with ACK jitter on one: Vegas 9.9 / 9.6 with none, 17.7 / 1.5 at 40 ms; BBR 15.0 / 4.1; Reno 12.5 / 7.0, no worse at 40 ms than at 20. L4S; learned and verified congestion control (Remy, Aurora, CCAC); coexistence. Four open problems.
  • Outro. Recap, payoffs, practice, problems, next part.

Companion material in this repository

The syllabus's plan for this partfrom SYLLABUS.md, the plan of record
  1. The transport problem; UDP against TCP.
  2. Reliability from scratch:
    • stop-and-wait and the alternating-bit protocol;
    • utilization (L/R)/(RTT + L/R), derived;
    • sliding windows: Go-Back-N and Selective Repeat;
    • sequence space ≥ 2 × window (proved).
  3. TCP: sequence numbers, cumulative ACKs, the handshake and SYN cookies, teardown and TIME_WAIT, flow control.
  4. RTT estimation (Jacobson/Karels EWMAs, Karn's rule, RTO).
  5. The 1986 collapse (32 kb/s → 40 b/s); Jacobson (1988): slow start, congestion avoidance, fast retransmit and recovery.
  6. AIMD and the Chiu–Jain phase plot (1989): AIMD converges to fair and efficient (proved geometrically, animated); MIMD and AIAD don't.
  7. The sawtooth and the Mathis formula ≈ (MSS/RTT)·√(3/2)/√p (derived); RTT unfairness.
  8. Router queues: drop-tail, bufferbloat, RED and CoDel; buffer sizing at RTT·C/√n (Appenzeller 2004).
  9. Modern congestion control: CUBIC; BBR (2016) and Kleinrock's optimal operating point; Vegas; DCTCP.
  10. Network utility maximization (Kelly 1998): TCP as a dual algorithm; proportional fairness (callback to Part 22's duality).
  11. DNS (Mockapetris 1983): hierarchy, caching, TTLs; Kaminsky's poisoning (2008).
  12. The web: HTTP/1.1 and head-of-line blocking; HTTP/2; QUIC (RFC 9000) and HTTP/3: streams over UDP, 0-RTT, migration; TLS 1.3 inside (callback to Part 30).
  13. CDNs and anycast; Zipf's law of requests, fitted on the novels' words.
  14. Our TCP fetching the novels over a lossy link: cwnd traces. Ledger row 14. Outro.

Computed: our rdt and TCP-lite under loss and reordering; utilization against window; Chiu–Jain trajectories; sawtooth throughput against Mathis; bufferbloat delays; BBR-lite against Reno-lite; NUM by dual ascent; the Zipf fit. Visuals: sequence diagrams with drops and retransmits; a window sliding over the byte stream; Chiu–Jain zig-zags toward the fairness line; the cwnd sawtooth; queues swelling. In practice: TCP tuning, CDNs, HTTP/2 and HTTP/3 deployments, DNS operations, Wireshark. Reading: Kurose & Ross ch. 2–3; Peterson & Davie ch. 5–6; Stevens; Srikant & Ying, Communication Networks; Grigorik, High Performance Browser Networking; Jacobson 1988; Chiu & Jain 1989; Mathis et al. 1997; Kelly, Maulloo & Tan 1998; Cardwell et al. 2016; Langley et al. 2017; Nichols & Jacobson 2012.

中文讲义

本讲的中文部分(与英文版对应)。

习题与解答
  1. 序列号空间。 证明:在可能丢包的 FIFO 信道上,序列号取模 S 时,选择重传正确当且仅当 W ≤ S/2,回退 N 正确当且仅当 W ≤ S − 1。

    解答

    选择重传的充分性:接收方期待 r, …, r + W − 1 时,发送方还可能发出的分组都落在 [r − W, r + W − 1] 内,因为发送方 的窗口基至少是 r − W(接收方已确认到 r − 1,而发送方在看到这些 ACK 之前发出的不会超过基 + W − 1),至多是 r。这个区间有 2W ≤ S 个数,取模 S 后互不相同;落在接收窗口内的编号就是它看上去的那个分组,落在下面的是旧的重复,再确认一次后丢弃。 必要性:让接收方收下 0, …, W − 1,而所有 ACK 都丢失;发送方重传 0,它模 S 等于 S,当 2W > S 时落在新窗口 [W, 2W − 1] 内,于是被当作分组 S 收下。回退 N 的接收窗口只有一个编号 r,发送方可能的编号在 [r − W, r] 内:W + 1 个,互不相同当且仅当 W + 1 ≤ S。若 W = S、所有 ACK 丢失、重传分组 0,期待分组 S 的接收方会收下它。我们的测试:S = 8 时,回退 N 的 W = 7 与选择 重传的 W = 4 在 10 次运行中全部正确,W = 8 与 W = 5 全部出错。

  2. 带超时的 Mathis 公式。 推导 Mathis 公式;再在每次丢包都只能靠 2 RTT 的超时发现时重做一遍。

    解答

    稳态下窗口在 W/2 个往返内从 W/2 线性升到 W,一个周期交付 (W/2)(3W/4) = 3W²/8 个分组,其中一个丢失: 3W²/8 = 1/p,W = √(8/(3p)),速率为 (3W/4)·MSS/RTT = (MSS/RTT)√(3/(2p))。若每次丢包改为停顿 2 RTT 的超时并从窗口 1 重新 开始,每个周期是:慢启动到 W/2(log₂(W/2) 个往返,约 W/2 个分组),再从 W/2 线性升到 W(W/2 个往返内 3W²/8 个分组), 再停顿 2 个往返。每周期分组数 ≈ 3W²/8 + W/2 = 1/p;每周期时间 ≈ W/2 + log₂(W/2) + 2 个往返。p 小时仍有 W ≈ √(8/(3p)), 速率按因子 (W/2)/(W/2 + log₂ W + 1) 下降;W 小时影响很大:p = 0.01(W ≈ 16)时速率约减半。这正是 Padhye 等人 1998 年建模 的情形。

  3. 四种规则。 证明 AIAD 与 MIMD 分别保持两个用户速率之差与之比;证明对任意 a > 0、0 < b < 1,AIMD 收敛。

    解答

    AIAD 下两个速率每轮改变相同的 ±a(直到有一个降到零),所以 x₂ − x₁ 不变;MIMD 下两者乘以同一个因子,所以 x₂/x₁ 不变。两者都不会从不公平的起点接近公平线。AIMD 下,增加不改变 d = x₂ − x₁,减少把它乘以 b。每个增加轮总和 s 增加 2a,所以从任何点出发,⌈C/(2a)⌉ 轮内就会超过 C;因此减少无限多次发生,k 次之后 |d| = bᵏ|d₀| → 0。收敛后 s 在约 bC 与 C + 2a 之间振荡,效率趋于区间 [b, 1]:b = 1/2 时平均负载约 3/4,我们测得 0.78。

  4. 三条串联链路。 手工求解三条容量为 1 的串联链路上的 Kelly 问题(对数效用,一条长流经过全部三条链路,每条链路一条 短流),并检验价格。

    解答

    由对称性每条链路价格都是 p,短流发送 1/p,长流 1/(3p)。每条链路都满:1/p + 1/(3p) = 1,所以 p = 4/3,短流得 3/4,长流得 1/4。KKT 条件:Σ log x 对 x 的导数 1/x 必须等于路径价格:短流 1/(3/4) = 4/3 = p,长流 1/(1/4) = 4 = 3p。 总量 9/4 = 2.25,而最大最小公平给四条流各 1/2,总量 2。我们的对偶上升:0.250 与 0.750。

  5. 动手:延迟确认。 给我们的 TCP 加上延迟确认(每两个报文段一个 ACK,或 40 ms 后)。慢启动、Mathis 常数和 BBR 的带宽 估计会怎样?

    解答

    解答要点。 在 tcp.py 中,接收方在每个分组离开瓶颈时确认它;改为缓存每隔一个的分组(带定时器)并一起确认,并让累积 ACK 为两个分组增加窗口(或者按 RFC 5681 允许的那样至多增加一个,区别就在这里)。按 ACK 计数时,慢启动每个往返增长 1.5 倍 而不是 2 倍,拥塞避免每个往返增加半个分组,所以 Mathis 常数 √(3/2) ≈ 1.22 变成 √(3/4) ≈ 0.87(Mathis 等人记作 b = 2)。 按字节计数(RFC 3465)可以恢复两者。BBR 的交付速率样本变得更突发,因为 ACK 两个两个地到达;它的最大值滤波器使它略微高估, 于是向队列多推一点数据。

  6. ★ 研究:时延与公平的权衡。 在我们的哑铃拓扑上,给一条流的 ACK 加上至多 D 的保序抖动,找出你能设计的任何算法为使两条 流的 Jain 指数保持在 0.9 以上所需的最小平均排队时延;画出它随 D 的变化,并与 2022 年的饥饿界比较。

    已知结果。 Arun、Alizadeh 与 Balakrishnan 证明:时延收敛的算法(排队时延收敛到宽度为 δ(C) 的范围内)在非拥塞时延超过 δ 时可以被饿死;所以在抖动 D 下要公平,要么平衡时延范围比 D 宽(因而队列至少约为 D),要么使用时延以外的信号(丢包、ECN)。 我们的测量给出几个点:Vegas(排队约 4.5 个分组)在 D = 40 ms 时份额降到 7%;Reno 保持 36%,但填满了缓冲区。未解决的是确切 的曲线:对每个 D,与给定公平度相容的最小时延,以及达到它的算法。一个起点是让算法有意让自己的时延在比 D 更大的范围内振荡 (如 Copa 的模式切换),并通过振荡测量自己的份额。报告 D = 0、5、10、20、40 ms 时的 Jain 指数与平均队列。

Build the film

python -m videos.cs.cs37.compute        # the part's numbers, into .cache/cs37
python tools/build.py cs37                  # render and assemble the film
EXPLAINER_TTS=silent python tools/qa_scene.py cs37 Hook   # one chapter, silent, with a contact sheet

Scenes: videos/cs/cs37. Setup: see the course page. Source of these notes: the README and the scenes' narration.

Build it
python -m videos.cs.cs37.compute
python -m unittest tests.test_cs37_transport
python tools/build.py cs37