Latency Numbers Worth Knowing
Latency approximations are standard published figures that give a rough sense of how long common operations take. Every figure in this lesson is an approximation, so every figure is worded with about.
Disk against memory for 1 MB
A spinning disk reads data from a rotating plate. For 1 MB, its figure is about 80 times the memory figure.
memory_ms = 0.25
disk_ms = 20
print("Memory, 1 MB:", memory_ms, "ms")
print("Disk, 1 MB:", disk_ms, "ms")
print("Disk is slower by a factor of:", disk_ms / memory_ms)A round trip across an ocean
Distance adds waiting time even when nothing else changes. The ocean figure is about 300 times the figure inside one data center.
local_ms = 0.5
ocean_ms = 150
print("Inside one data center:", local_ms, "ms")
print("Across an ocean:", ocean_ms, "ms")
print("Ocean is slower by a factor of:", ocean_ms / local_ms)An SSD against memory for 1 MB
An SSD is a device with no moving parts that keeps data. For 1 MB, its figure is about 4 times the memory figure.
memory_ms = 0.25
ssd_ms = 1
print("Memory, 1 MB:", memory_ms, "ms")
print("SSD, 1 MB:", ssd_ms, "ms")
print("SSD is slower by a factor of:", ssd_ms / memory_ms)Example
pairs = [
("Disk vs memory", 20, 0.25),
("Ocean vs data center", 150, 0.5),
("SSD vs memory", 1, 0.25),
]
for name, slower, faster in pairs:
print(name, ":", slower / faster, "x")Key points
- Nanosecond: a billionth of a second, shortened to ns.
- Millisecond: a thousandth of a second, shortened to ms.
- Memory: the fast place a running program keeps its working data, also called RAM.
- Data center: a building that holds many computers in one place.
- Round trip: the trip a message makes when it goes out and comes back.
In this example, each slower time is divided by its faster partner. Each result is one comparison number for its pair.
Note
these figures guide comparisons between operations, and no real system matches them exactly.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Standard latency approximations
| Operation | Time, about |
|---|---|
| One read from memory (RAM) | about 100 nanoseconds |
| Read 1 MB from memory | about 0.25 milliseconds |
| Read 1 MB from an SSD | about 1 millisecond |
| Find and read 1 MB on a spinning disk | about 20 milliseconds |
| Round trip inside one data center | about 0.5 milliseconds |
| Round trip across an ocean | about 150 milliseconds |
Exercise
About how many times longer is a round trip across an ocean than a round trip inside one data center?