Loading
0x80Lesson 9 of 14

Measure latency and throughput

Find out why more bandwidth doesn't always make the web faster.

20 min 6-question quiz 2 code exercises
By the end of this lesson you can
  • Distinguish latency, bandwidth and throughput.
  • Estimate a round-trip time from distance.
  • Explain why small web requests are limited by latency rather than bandwidth.

You upgrade from 100 Mb/s to 1 Gb/s, and big downloads get much faster. Yet websites feel about the same. Is your provider cheating you?

Probably not. A network has two different kinds of speed, and they're often confused.

A highway for bits

Picture a highway. Bandwidth is the number of lanes: how much can flow at once, measured in bits per second. Latency is how long one car takes to make the trip, measured in milliseconds. Adding lanes doesn't make a car arrive sooner.

Throughput is what you actually get, which is usually lower than the bandwidth because of round trips, loss and congestion.

Where latency comes from

Light in fiber travels about 200 km per millisecond, around two thirds of its speed in a vacuum. No upgrade can beat that, so physics sets a floor on every round trip.

The delay of a packet has four parts: propagation (the distance), transmission (pushing the bits onto the link), queuing (waiting behind other traffic) and processing (a small cost at each router).

latency.py
1FIBER_KM_PER_MS = 200
2
3def round_trip_ms(distance_km):
4    return 2 * distance_km / FIBER_KM_PER_MS
5
6def send_ms(size_kb, megabits_per_second):
7    return size_kb * 8 / megabits_per_second
8
9print(f"New York to London: {round_trip_ms(5600):.0f} ms minimum")
10print(f"500 kB at 100 Mb/s: {send_ms(500, 100):.0f} ms")
11print(f"500 kB at 1000 Mb/s: {send_ms(500, 1000):.0f} ms")
Output
New York to London: 56 ms minimum
500 kB at 100 Mb/s: 40 ms
500 kB at 1000 Mb/s: 4 ms

Try it

What is a page load waiting for?

A web page needs several round trips in a row: DNS, TCP, TLS, then the request. Try this:

  1. Set the server to Across an ocean and drag bandwidth from 1 up to 1000 Mb/s. Where does the improvement stop?
  2. Now hold the bandwidth at 100 and switch the server between Same city and Other side of the world.

The chart compares your round-trip time with half of it. Which is worth more: ten times the bandwidth, or a server twice as close?

Where the server is
Loading a 500 kB page takes 310 ms
  • Waiting on round trips: 150 ms
  • Sending data: 160 ms
Round-trip time
30 ms
Time spent waiting
48%
  • Round trip of 30 ms
  • Half that: 15 ms
01,2502,5003,7505,000151025501002505001000Bandwidth (Mb/s)Load time (ms)
Show the numbers as a table
Bandwidth (Mb/s)Round trip of 30 msHalf that: 15 ms
14,1504,075
5950875
10550475
25310235
50230155
100190115
25016691
50015883
100015479

This is why large sites use content delivery networks (CDNs): they place copies near you to cut the distance. It's also why newer protocols work so hard to remove round trips. TLS 1.3 saves one compared with TLS 1.2, and HTTP/3 combines the transport and TLS handshakes.

Keeping a fast pipe full

The window from the last lesson connects these ideas. To keep a link busy, a sender needs a full round trip's worth of data in flight. That amount is the bandwidth-delay product:

in-flight data = bandwidth × round-trip time

At 100 Mb/s and 80 ms, that's 8 megabits, or 1 MB. A sender whose window is smaller than this can't use the whole link, however fast it is.

Key takeaways

  • Bandwidth is capacity, latency is delay, and throughput is what you actually get.

  • Distance sets a hard floor on latency: about 1 ms of round trip per 100 km of fiber.

  • Small transfers are limited by round trips, and large ones by bandwidth.

Lesson quiz

6 questions · pass with 5 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: model networking concepts

Use small Python programs to model packet, address, and protocol behavior. These exercises run locally in your browser and do not send network traffic.

Exercise 1

Estimate a round trip

+25 XP

Read a distance in kilometers and print the minimum round-trip time through fiber, as a whole number of milliseconds, in the form 56 ms. Light in fiber covers about 200 km per millisecond.

  • An ocean crossing
  • A nearby city
main.py
Loading editor…

Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.

Exercise 2

Find the bottleneck

+25 XP

Read a page size in kB, a bandwidth in Mb/s, a round-trip time in ms, and a number of round trips, one per line. Print the total load time in whole milliseconds, then whether the page is latency-bound or bandwidth-bound depending on which part takes longer.

540 ms
latency-bound
  • A small page, far away
  • A big download
main.py
Loading editor…

Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…