$ ls ~yifei/notes/


Posted on:

Last modified:

L1 缓存访问0.5 ns0.5ns
分支预测错误5 ns5ns
L2 缓存访问7 ns7ns
互斥锁/解锁25 ns25ns
内存访问100 ns100ns
使用 Zippy 压缩 1KiB3,000 ns3 µs
通过 1 Gbps 网络发送 2KiB20,000 ns20 µs
SSD 随机读取150,000 ns150 µs
内存中连续读取 1 MB250,000 ns250 µs
同一个数据中心的来回500,000 ns0.5 ms
从 SSD 上连续读取 1 MB*1,000,000 ns1 ms
机械磁盘寻道10,000,000 ns10 ms
机械磁盘连续读取 1 MB20,000,000 ns20 ms
发送数据包 加州->荷兰->加州150,000,000 ns150 ms
  • 假设 ~1GB/sec SSD

如果把这些时长都乘以 10 亿的话:

L1 缓存访问0.5 s一次心跳 (0.5 s)
分支预测错误5 s打个哈欠
L2 缓存访问7 s打个长哈欠
互斥锁/解锁25 s冲一杯咖啡
内存访问100 s刷牙
使用 Zippy 压缩 1KiB50 min一集电视剧(包括广告)
通过 1 Gbps 网络发送 2KiB5.5 hr从午餐到下午工作结束
SSD 随机读取1.7 days一个普通的周末
内存中连续读取 1 MB2.9 days一个长周末
同一个数据中心的来回5.8 days一个普通假期
从 SSD 上连续读取 1 MB*11.6 days等快递等了两周
机械磁盘寻道16.5 weeks大学里的一个学期
机械磁盘连续读取 1 MB7.8 months几乎能造个人了
上面两个加起来1 year整整一年
发送数据包 加州->荷兰->加州4.8 years快能读个博士了

可视化网页: https://people.eecs.berkeley.edu/~rcs/research/interactive_latency.html


了解这些时间的量级有助于比较不同的解决方案。通过这些数字,你可以看出来从远程服务器的内存中读一些数据时比直接从硬盘上读取快的。在一般的程序中,这也就意味着使用磁盘存储比使用数据库服务器要慢,因为数据库通常把所有东西都放在内存里了。而且这也说明了为什么在服务全球客户的时候 CDN 至关重要。从北美到欧洲的一个 ping 就要花上 100+ ms,所以从地理上来说,内容应该是分布式部署的。

The idea is more about knowing the scale of time it takes to help compare different solution. With those number you can see that it's faster to get data in memory from a distant server than to read the same data from disk. In common application that means using disk storage is less efficient that storing it in a database on an other server, since it usually keeps almost everything in memory. It also tells a lot about why CDN are needed if you are serving client worldwide. A ping from North America to Europe will always takes 100+ ms, so having geographically distributed content is a good idea.

对于互斥锁的开启锁定时间 mutex lock/unlock time is important for anyone writing code that depends on code that is accessing the same data structures at the same time. If you don't know that there is a considerable cost to writing such code, now you do; and this number can quantify it.







  • 延迟表示通过管道需要花费的时间
  • 带宽表示管道的宽度
  • 每秒钟流过的水的数量就是吞吐

吞吐 = 延迟 x 带宽

然而不幸的是,吞吐这个词经常被用作两个意思。有时候吞吐的意思是指的系统总荷载,有时候又指 的是每秒吞吐量,也就是带宽(当然单位不同).


  1. https://gist.github.com/hellerbarde/2843375
  2. https://softwareengineering.stackexchange.com/questions/312485/how-can-jeff-deans-latency-numbers-every-programmer-should-know-be-accurate-i
  3. https://stackoverflow.com/questions/36949735/what-is-the-difference-between-latency-bandwidth-and-throughput
WeChat Qr Code

© 2016-2022 Yifei Kong. Powered by ynotes

All contents are under the CC-BY-NC-SA license, if not otherwise specified.

Opinions expressed here are solely my own and do not express the views or opinions of my employer.

友情链接: MySQL 教程站