0 day streak

I/O models

I/O models are the different ways a program can wait on slow things like network sockets and disks without wasting the machine. The simplest is blocking I/O: a thread calls read and sleeps until data arrives, so serving many connections means a thread each, which gets expensive by the thousands. The alternative is non-blocking I/O with readiness notification: one thread registers many sockets with the kernel, through epoll on Linux or kqueue on macOS, asks which are ready, and handles only those. That event loop is how nginx and Node.js serve tens of thousands of connections on a few threads. Newer interfaces like io_uring let you submit operations and collect results in batches.

In this lesson: An event-loop sim comparing 1,000 sockets handled by blocking threads vs epoll.