Cianplan

Level 0: Orientation & prerequisites · L0.2 OS & hardware basics for architects

Async I/O and the event loop

Explain why non-blocking I/O lets one thread serve many connections.

12 min · Free

What you take away

  • A blocking call parks its whole thread until the answer arrives; a non-blocking call returns immediately and the OS reports back when the data is ready.
  • One event loop can hold tens of thousands of waiting connections, because waiting costs a few hundred bytes instead of a ~1 MB thread stack.
  • Async raises throughput for I/O-bound work. It does not make any single request faster.
  • One CPU-heavy computation on the loop stalls every connection on it — the loop's one fatal failure mode.

How the class is laid out

  1. The problem
  2. The simple version
  3. How one thread serves ten thousand connections
  4. Check your understanding