Latency Numbers Every Programmer Should Know

在线预览地址:Latency Numbers Every Programmer Should Know

From Google SRE book

OperationTime in nsTime in ms (1ms = 1,000,000 ns)
L1 cache reference1
Branch misprediction3
L2 cache reference4
Mutex lock/unlock17
Main memory reference100
Compress 1 kB with Zippy2,0000.002
Read 1 MB sequentially from memory10,0000.010
Send 2 kB over 10 Gbps network1,6000.0016
SSD 4kB Random Read20,0000.020
Read 1 MB sequentially from SSD1,000,0001
Round trip within same datacenter500,0000.5
Read 1 MB sequentially from disk5,000,0005
Read 1 MB sequentially from 1Gbps network10,000,00010
Disk seek10,000,00010
TCP packet round trip between continents150,000,000150

Therefore, it is possible to read:

  • sequentially from HDD at a rate of ~200MB per second
  • sequentially from SSD at a rate of ~1 GB per second
  • sequentially from main memory at a rate of ~100GB per second (burst rate)
  • sequentially from 10Gbps Ethernet at a rate of ~1000MB per second

Back of the Envelope Calculations

Quick tips: Use numbers based on the decimal system to run numbers in your head. Sample calculation:

  • What is the overall latency of retrieving 30 256kB images from one server?

Naïve design: do all the work on one machine - dominated by disk seek time.

Reads required to generate page30 images / 2 disks per machine = 15
Time to read one image from HDD(256KB / 1MB) * 5 ms + 10 ms seek = 11.28 ms
Approximate time to generate results15 reads * 11.28 ms = 169.2 ms

One HDD-based server can generate 1000 ms / 169.2 ms ~= 5 result pages per second.