Reading time · 8 min

Where Network Latency Comes From

Where Network Latency Comes From

A ping from my apartment in Paris to a server near New York takes 87 ms, but light could make that round trip in 58. Where are my missing 28 ms? Can I buy back some of them?

Where Latency Comes From

Latency is the time it takes for a message to travel from one point to another, usually measured in ms or μs. Low latency means faster responses. Groundbreaking, I know.

Let’s follow our message and find out who stole the other 28 ms. During its trip, the message spends time in four places: on the wire (propagation), getting onto the wire (transmission), inside routers (processing), and waiting in line (queuing).

Propagation

Propagation is the time for the signal to physically travel the distance. The propagation formula is:

propagation=distancesignal speed\text{propagation} = \frac{\text{distance}}{\text{signal speed}}

Light travels at ~200,000 km/s in fiber and New York is 5,840 km away from Paris, so one way should take 29 ms, and 58 ms for the round trip.

But 29 ms is the best case. It assumes a cable running straight from Paris to New York. Real cables don’t. We can see where the cables actually run on submarinecablemap.com.

Notice that the size of the message and the bandwidth are missing from the formula because no matter the size of the message, the time for the first bit to reach New York is identical. Bandwidth only decides how fast the rest follows.

Transmission

Transmission is the time to push all the bits of the message onto the link. The formula is:

transmission=message sizebandwidth\text{transmission} = \frac{\text{message size}}{\text{bandwidth}}

The result grows with message size and shrinks with more bandwidth. Our ping is 64 bytes on my MacBook and my fiber plan is about 1 Gbps or 125,000,000 B/s. With this configuration our message should take 0.5 μs.

As we can see, distance doesn’t matter here, because transmission ends when the last bit leaves. After that, it’s propagation’s job.

Processing

Processing is the time each router spends reading the packet header and choosing the next link. It’s usually a few μs per router, but we have zero control over this step.

As this step is quite fast, going through a dozen routers shouldn’t take more than 0.1 ms.

Queuing

Queuing is the time a packet spends waiting in a router buffer. It occurs when packets arrive in the router faster than they can be sent out. The usual time spent here ranges from nothing to tens of ms depending on the load.

This step is the most unpredictable part, and it’s the main cause of tail latency.

So Where Did the Time Go?

Now we have the tools to answer our question! We need to identify where those 28 ms went.

As the round trip (RTT, for round-trip time) is the sum of the four steps we just saw, once for the client request, once for the server response, we can estimate the time spent in each step from it.

text
RTT = propagation + transmission + processing + queuing    (both ways)

To get the RTT, we ping a server near New York (here: nj-us-ping.vultr.com), in New Jersey, which changes the math by less than half a millisecond, because it’s only about 40 km further from Paris than Manhattan. We repeat this 50 times (-c means “count”), with 0.2 s between each ping (-i stands for “interval”).

bash
ping -c 50 -i 0.2 nj-us-ping.vultr.com
text
PING nj-us-ping.vultr.com (108.61.149.182): 56 data bytes
[more lines]

--- nj-us-ping.vultr.com ping statistics ---
50 packets transmitted, 50 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 85.379/86.679/93.580/1.788 ms

Queuing: Average Minus Minimum

As we can see on the last line, the minimum RTT is 85.379 ms and the average RTT is 86.679 ms.

Out of the four steps, queuing is the only one that changes from one ping to the next. So the fastest ping is the one that waited the least. That means the minimum is our best case (with almost no queuing), whereas the average includes the usual wait. So the difference between the two tells us how long we wait on average compared to the best case. Here we waited about 1.3 ms (86.679−85.379≈1.386.679 - 85.379 \approx 1.3 ms).

Transmission and Processing: Too Small to Matter

Transmission only shows up if we ping with bigger packets (-s 1400) because for our 64-byte ping, it’s only a few μs.

For processing, as no command isolates the time a router spends reading a header, we can’t measure it from the outside. It usually takes a few microseconds per router, so even a dozen routers stay well under a millisecond. We can ignore both.

Propagation: What’s Left

With queuing out of the minimum, and transmission and processing too small to matter, the minimum RTT is almost pure propagation. Some of it is spent before the message even leaves my apartment. Let’s run two quick measurements to see how much:

bash
ping -c 30 -i 0.2 192.168.1.1
traceroute -I nj-us-ping.vultr.com
text
round-trip min/avg/max/stddev = 4.701/5.607/9.972/1.265 ms

 1  192.168.1.1                            5.350 ms
 7  81.52.170.48                           6.516 ms
 8  be40.br03.nyc06.as3491.net             85.810 ms
13  108.61.149.182.vultrusercontent.com    85.712 ms

As we can see, my Wi-Fi and box cost about 4.7 ms. Orange’s own network adds about 1.8 ms (still in Paris). The next router that answers is already in New York: the whole Atlantic fits in a single hop (seven-league boots would be jealous).

To get the duration of the trip across the ocean, we need to remove those local costs from the minimum: 85.4−4.7−1.8≈78.985.4 - 4.7 - 1.8 \approx 78.9 ms round trip, so about 39.5 ms one way. At 200,000 km/s, that’s about 7,900 km of cable, against 5,840 km in a straight line. The detour alone costs about 20.5 ms.

The Verdict

Where the time wentCost
Queuing~1.3 ms
Wi-Fi and box~4.7 ms
Orange’s network~1.8 ms
Cable detour (propagation)~20.5 ms
Transmission and processinga few μs
Total~28.3 ms

Be careful. These numbers are estimates: we got propagation by subtracting everything else, not by measuring it directly. But the verdict holds because most of the missing time is distance, just more of it than the map suggests. And distance, unlike bandwidth, is something no upgrade can buy back. (Bandwidth will get its moment, just not with a 64-byte ping.)

When Bandwidth Does Matter

Wait, did I just say bandwidth doesn’t matter? Not quite! Remember, bandwidth decides how fast the rest of the message follows the first bit. So for a 64-byte ping, there’s no “rest”. For a 10 MB file the rest is almost… everything! Let’s see where the switch happens.

Let’s compute how long messages of growing size would take from Paris to New York, one way, over a single 1 Gbps link with the 29 ms of straight-line propagation from earlier:

text
transmission  = message size (bits) / bandwidth (bits per second)
delivery time = transmission + propagation
share         = transmission / delivery time
share of delivery time at 1 Gbps
share of delivery time at 1 Gbps
propagationtransmission
64 B100 %0 %
1 KB100 %0 %
100 KB97 %3 %
1 MB78 %22 %
3.6 MB50 %50 %
10 MB27 %73 %
100 MB4 %97 %
1 GB0 %100 %

The switch happens around 3.6 MB, where transmission catches up with propagation (1 Gbps×29 ms1\,\text{Gbps} \times 29\,\text{ms}). Below it, distance wins and doubling the bandwidth changes nothing we’d notice: a 1 KB message takes 29 ms at 1 Gbps and still 29 ms at 2 Gbps. Above it, bandwidth wins and doubling it almost halves the time: a 1 GB file drops from 8,029 ms to 4,029 ms.

(This is the clean version: one link, no queuing, and no TCP. Real downloads are slower than this, for reasons we’ll get to in the next article.)

Takeaways

Most of the time a message spends on the network is distance, and distance is the one thing we can’t buy back. Bandwidth helps with big transfers, but most of what distributed systems send is small: requests, acks, heartbeats, Raft votes. For those, the 64-byte ping is the honest model, and distance wins every time.

So if we can’t make a round trip cheaper, there’s only one lever left: make fewer of them. That’s the subject of the next article, Count Round Trips, Not Bytes (soon).