J’ai lu un article il y a peu, et je ne le retrouve pas. Il contenait un passage qui comparait les temps d’accès au cache L1, L2, L3 des processeurs, à la mémoire RAM, aux disques durs, au réseau...
Ça vous dit quelquechose ?
J’ai lu un article il y a peu, et je ne le retrouve pas. Il contenait un passage qui comparait les temps d’accès au cache L1, L2, L3 des processeurs, à la mémoire RAM, aux disques durs, au réseau...
Ça vous dit quelquechose ?
yo severo :)
tu l’avais repéré par ici cet article ? Il était dans quelle langue ?
tu l’avais repéré par ici cet article ?
je crois que oui, mais pas sur :-P
Il était dans quelle langue ?
En anglais je crois.
Désolé, ma mémoire est pas terrible...
J’ai trouvé !!! C’était pas un article, mais le livre
▻https://leanpub.com/nodecraftsman
Le passage en question :
Blocking and non-blocking operations
From the understanding of this conceptual model, we can get to understanding the difference between blocking and non-blocking operations. The key to understanding these is the realization that every synchronous operation results in a blocking operation. That’s right, even an innocent
console.log(’Hello World’);
results in a blocking operation - while the Node.js process writes the text to the screen, this is the only thing that it does. There is only one single piece of JavaScript code that can be executed within the event loop at any given time.
The reason this doesn’t result in a problem in the case of a console.log() is that it is an extremely cheap operation. In comparison, even the most simple IO operations are way more expensive. Whenever the network or harddrives (yes, including SSDs) are involved, expect things to be incredibly much slower compared to operations where only the CPU and RAM are involved, like var a = 2 * 21 . Just how much slower? The following table gives you a good idea - it shows actual times for different kind of computer operations, and shows how they relate to each other compared to how time spans that human beings experience relate to each other:
1 CPU cycle 0.3 ns 1 s
Level 1 cache access 0.9 ns 3 s
Level 2 cache access 2.8 ns 9 s
Level 3 cache access 12.9 ns 43 s
Main memory access 120 ns 6 min
Solid-state disk I/O 50-150 μs 2-6 days
Rotational disk I/O 1-10 ms 1-12 months
Internet: SF to NYC 40 ms 4 years
Internet: SF to UK 81 ms 8 years
Internet: SF to Australia 183 ms 19 years
OS virtualization reboot 4 s 423 years
SCSI command time-out 30 s 3000 years
Hardware virtualization reboot 40 s 4000 years
Physical system reboot 5 min 32 millenia
So, the difference between setting a variable in your code and reading even a tiny file from disk is like the difference between preparing a sandwich and going on vacation for a week. You can prepare a lot of sandwichs during one week of vacation.
And that’s the sole reason why all those Node.js functions that result in IO operations also happen to work asynchronously: it’s because the event loop needs being kept free of any long-running operations during which the Node.js process would practically stall, which would result in unresponsive applications.
#node.js #javascript #IO #access_time #harddisk #ram