Broadcasting events
It is always good to have an accurate understanding of the total eventual cost of asking for a service to be performed.
I/O is expensive. In the following chart (taken from Ryan Dahl's original presentation on Node) we can see how many clock cycles typical system tasks consume. The relative cost of I/O operations is striking.
L1 cache |
3 cycles |
L2 cache |
14 cycles |
RAM |
250 cycles |
Disk |
41,000,000 cycles |
Network |
240,000,000 cycles |
The reasons are clear enough: a disk is a physical device, a spinning metal platter that buses data at a speed that cannot possibly match the speed of an on-chip or near-chip cache moving data between the CPU and RAM (Random Access Memory). Similarly, a network is bound by the speed in which data can travel through its connecting "wires", modulated by its controllers. Even through fiber optic cables, light itself needs 0.1344 seconds to travel around the world. In a network used by billions of people regularly interacting...