
Latency Numbers Every Programmer Should Know - ashitlerferad
https://gist.github.com/jboner/2841832
======
n00b101
Relevant: Grace Hopper explains Nanoseconds

[1]
[https://www.youtube.com/watch?v=JEpsKnWZrJ8](https://www.youtube.com/watch?v=JEpsKnWZrJ8)

~~~
hinkley
Agreed. I love that bit, especially how well it plays to her target audience.

------
rdslw
This is an exercise I recommend every developer take. [https://computers-are-
fast.github.io/](https://computers-are-fast.github.io/)

It shows you by series of questions, how fast code run, what is speed of ram
vs cache, ram vs hdd, file vs sql read.

Highly recommended.

------
pcmonk
This is a great list. The one that I see people ignore the most is the fact
that spinning disk access is 20x the cost of a datacenter roundtrip. If you
need low-latency persistence, something like Apache Kafka is a much better
solution than a disk (as long as your scale justifies it).

~~~
dleibovic
Kafka is backed by spinning disks though. Am I missing something?

~~~
hadsed
Generally Kafka takes advantage of the OS page cache and the fact that its
data is sequential. The reason you can back Kafka effectively with spinning
disks is because Kafka is just an immutable log.

OTOH you won't always have sequential access so services that store data in
memory cover some of those other cases (eg a KV store like Redis).

------
1maginary
This is apparently from 2012.

How outdated are some of these numbers?

According to this[1] source (linked in the gist comments), ping is down to
144ms from LA to Amsterdam.

[1]: [https://wondernetwork.com/pings/](https://wondernetwork.com/pings/)

~~~
dyladan
I believe that the gist is not really meant to provide accurate numbers in
every case. Especially with things like network latency, it is very difficult
to say that any time is the 'correct' time because it will be different in any
case. The real purpose of the gist, which is posted at regular intervals here,
is to illustrate the order of magnitude differences between e.g. the L1 cache
and L2 cache latency. It is meant to get a programmer to think about cache
locality. If I can keep something in L1/L2 cache, it will be orders of
magnitude faster than something that needs to make regular round trips to main
memory, which is orders of magnitude faster than something that needs to make
regular round trips to disk, and so on.

~~~
1maginary
I guess I took the title too literally. I would expect every competent
programmer to know what you explained, and that is probably what the title was
alluding to.

Thanks for clarifying.

------
jstelly
It's worth noting that opening a file can have much longer latency than the
disk read number in this table on consumer machines due to two factors: a)
power policy causes hard drive to power off. Spin up time is on the order of
seconds. b) user installed virus scanner hooks your process' file open or read
to perform scan. This can typically take time on the order of hundreds of
milliseconds.

These numbers are also important when writing software that runs on consumer
PCs where real-time performance is a feature (e.g. most PC games).

------
ape4
So I should store everything in a mutex. Gotcha.

------
PhilWright
Not sure the numbers make much sense...

    
    
        Main memory reference - 100ns
        Compress 1K bytes with Zippy - 3,000ns
    

So it takes 30 main memory accesses to zip up 1K? Not likely.

~~~
foota
If you have 32 byte cache lines and no hardware prefetch then yes.

------
shakencrew
Previous discussion on Hacker News:
[https://news.ycombinator.com/item?id=4047623](https://news.ycombinator.com/item?id=4047623)

